locked
server-side includes RRS feed

  • Question

  • User1615613230 posted

    Yes, 

    Server-side includes are not the Microsoft's preferred technology for code re-use. 

    http://msdn.microsoft.com/en-us/library/3207d0e3(v=VS.100).aspx

    " Although you can still use the #include tag for the purpose of code reuse (by placing common server-side code, controls, or HTML markup within a file to include in other Web pages), often the preferred approach in ASP.NET is to use Web user controls. User controls provide an object-oriented programming model and much greater functionality than server-side includes."

    And others have addressed similar questions before...

    http://stackoverflow.com/questions/894720/asp-net-equivalent-of-server-side-includes

    ...but I have a scenario (too complicated to describe in a little post)
    where suffice it to say, the use of a Server-side include would come in very handy,
    and user controls won't work with the data access procedures. 

    If I do use server-side includes, what are the dangers?
    Is it a completely foolish idea?  

     

     

    Thursday, December 9, 2010 10:13 PM

Answers

  • User-952121411 posted

    I read through that post to see how that developer was too trying to figure out some way to get that data from the database into .NET and was also new to .NET.  I think a lot of questions are answered inadvertently through some of the tried and true Object Oriented Design principals when applied to .NET languages.  Through concepts like separation of concerns you automatically make distinct logical and physical delineations of your code. The way we connect all of the pieces back together are through "References" in VS.NET.  An "assembly reference" is one where a project contains reference to and access to a separately built and compiled .dll. A "Service or Web Reference" is a reference to say a WCF or .asmx web service via auto-generated proxy classes that allow your main calling code access to that "separated or reusable" code in much the same manner.

    Now we connect the dots back to your original question of how to reuse code that is in a separate file/class/service etc. The easiest 1st step is to take any (#include) type code and place it in its own class say within the "App_Code" folder within the same project and just instantiate an instance of the class and your done! The next step after understanding the previous one, would be to port that code into a separate project in VS.NET and then add it is a "Reference" (via VS.NET Right click "References" and say add reference; select the separate project from the "Projects" tab). The next step in progressing to make this code widely available to your apps would be to migrate it into a WCF service.  Once the service was built and deployed you can add it as a "Service Reference" to your project and create an instance via the proxy classes of your service and have access to that shared code.

    You don't kneed to do each step above, but it shows the different ways in that you can share or reuse code within your applications or across multiple applications in replacement of old server side includes to other "library" or code files.

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 13, 2010 11:14 AM

All replies

  • User-952121411 posted

    ...but I have a scenario (too complicated to describe in a little post)
    where suffice it to say, the use of a Server-side include would come in very handy,
    and user controls won't work with the data access procedures
     

    Dare I draw conclusions, but I think this is a classic case of applying an old mentality to a new era.  There are so many ways of re-using or including external code in things like, separate binaries (.dlls), services, additional classes (App_Code folder even), user controls, etc that make using the server side includes obsolete.  Maybe if you elaborate a bit on the nature of what code needs to be included for a possible recommendation on where that code could sit best and be available to your application.

    Friday, December 10, 2010 10:27 AM
  • User712082397 posted

    Apply KIS (Keep It Simple) to your complicated scenario and try to break it down to manageable components.

    As some other people have suggested try to create a control, assemble, service etc and utilize that instead of SSI.

    Friday, December 10, 2010 1:22 PM
  • User1615613230 posted

    @atconway: your conclusion seems perfectly valid to me! (Though I will say SSI offers a certain simplicity and less work
    than the other recommended strategies.)

    Anyway, part of my conundrum is detailed over here: http://stackoverflow.com/questions/4286933 

     

    Friday, December 10, 2010 11:21 PM
  • User-952121411 posted

    I read through that post to see how that developer was too trying to figure out some way to get that data from the database into .NET and was also new to .NET.  I think a lot of questions are answered inadvertently through some of the tried and true Object Oriented Design principals when applied to .NET languages.  Through concepts like separation of concerns you automatically make distinct logical and physical delineations of your code. The way we connect all of the pieces back together are through "References" in VS.NET.  An "assembly reference" is one where a project contains reference to and access to a separately built and compiled .dll. A "Service or Web Reference" is a reference to say a WCF or .asmx web service via auto-generated proxy classes that allow your main calling code access to that "separated or reusable" code in much the same manner.

    Now we connect the dots back to your original question of how to reuse code that is in a separate file/class/service etc. The easiest 1st step is to take any (#include) type code and place it in its own class say within the "App_Code" folder within the same project and just instantiate an instance of the class and your done! The next step after understanding the previous one, would be to port that code into a separate project in VS.NET and then add it is a "Reference" (via VS.NET Right click "References" and say add reference; select the separate project from the "Projects" tab). The next step in progressing to make this code widely available to your apps would be to migrate it into a WCF service.  Once the service was built and deployed you can add it as a "Service Reference" to your project and create an instance via the proxy classes of your service and have access to that shared code.

    You don't kneed to do each step above, but it shows the different ways in that you can share or reuse code within your applications or across multiple applications in replacement of old server side includes to other "library" or code files.

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 13, 2010 11:14 AM