General discussion

  • Creator
    Topic
  • #2257156

    ASP.NET Equivalent of Server-Side Includes?

    Locked

    by underground_in_tn ·

    My company’s website is already ASP-based, but we are creating new pages in ASP.NET where it makes sense. But I’m having trouble coding the .NET pages to work with the old ASP pages due to the fact that .NET doesn’t support server-side includes. Let me explain:

    In the part of the website where users have logged in, we are storing a very few pieces of data in session variables, then referencing them as needed on each page. Each page includes an INC file that contains code to check a particular session variable, and if it’s not populated because the user hasn’t logged in or his session has expired, direct him to the appropriate “session expired” notice page. If it is populated, a series of other variables (Dim’d in the INC file and referenced later in each page) are populated according to the contents of another session variable.

    How do I accomplish the same thing in ASP.NET? I could put this into a custom code snippet, but while that’s nice for when I first create a new page, it’s taking one step backwards as far as code reuse and ease of maintenance goes.

    Or, I could rework this as a class and make those INC variable as properties of the class, but classes can’t directly access session variables, meaning I can’t populate the properties in the New constructor. So I’d have to duplicate code in each page that uses the class to populate those properties in the Page_Load sub, and now I’ve got a different set of ease-of-maintenance issues.

    There has to be another way to do this in .NET. Isn’t there?

All Comments

  • Author
    Replies
    • #3201214

      One way…

      by onbliss ·

      In reply to ASP.NET Equivalent of Server-Side Includes?

      …if I understood your issue correctly here is what I think you can do to avoid duplicating the code in each page.

      1)Create a base page, by creating a class that derives of System.Web.UI.Page, and place your code to check the session variable and other common stuff in the Page_Load. Let’s call this page as [b]AppBasePage[/b]

      2)Then you derive all your pages of this AppBasePage class.

      This would also ease out your maintenance issue, any future change would be just at the base page level. And each derived page still can access the base page members and act differently (if necessary).

      Let me know if this works out for you.

      edited: clarity and punctuation

      • #3201117

        At the risk of exposing my ignorance…

        by underground_in_tn ·

        In reply to One way…

        … can you tell me how, or point me to a sample in the MSDN help or a web site? I am very new to ASP.NET. Geez, I sound like I’m trying to get you to do my work for me, but I’m really not. I just need a lot of detail until I find my way around .NET.

        With my project open, I’ve added a new class, but I’m not sure how to make it derive from System.Web.UI.Page. I clicked Website > Add Reference … and double-clicked System.Web (I don’t see System.Web.UI.Page in the Add Reference window), but I can’t tell if that did anything at all. Am I heading in the right direction?

        edited to add disclaimer and more groveling…

    • #3281517

      An easy alternative

      by kirkk ·

      In reply to ASP.NET Equivalent of Server-Side Includes?

      >NET 2.0 should make this easier, but if you’re still on 1.x you can create a Header.ascx and Footer.ascx user controls, which just drop onto the pages at top and bottom.

      Caveats: you can’t include any input controls in the header or footer, because the form tags with runat=server have to be on the page – you can’t split them up and put the open tag in the header and close tag in the footer. Also, working with a split table can be tricky.

    • #3281405

      ASP Session vars <> .Net Session vars

      by reidb ·

      In reply to ASP.NET Equivalent of Server-Side Includes?

      I’m interested in the part of the question about using classic ASP session vars and .Net session vars. We too are transitioning, page-by-page from classic ASP to ASP .Net and need to share session data across both types of pages on the same domain.

      Anyone have experience or a recommendation?

      Thanks/Bob

      • #3221467

        One way

        by callred ·

        In reply to ASP Session vars <> .Net Session vars

        You may have already thought of this, but…

        Since you are migrating to ASP.NET anyway, you could just re-implement the session handling calls in your classic asp page(s) to write their info to a database table (with the ASP.NET session table schema). Then, since ASP.NET has built in database-backed sessions, there would be virtually no work needed on that end.

        Of course you could just use a centralized file share of some sort, with xml (or other format) file-based session management. But then, its a customized session management solution on both ends (asp and asp.net).

        • #3221927

          Thanks for the idea

          by reidb ·

          In reply to One way

          I’m finding that you can handle this via cookies, database, ISAPI, or combinations thereof.
          Thanks/Bob

        • #3221924

          A persistent media is better for Session mgmt between heterogenous apps

          by ganesh ·

          In reply to Thanks for the idea

          I would recommend a file or a database to share session data rather than cookies. While it is another call to the database or fileshare, it benefits to go with anytype of data to be stored in session variables.

    • #3221925

      Embrace the New Paradigm

      by careed ·

      In reply to ASP.NET Equivalent of Server-Side Includes?

      The ASP.NET equivalent is user controls (ASCX). However, this is not a one-to-one switch. Note that ASP/VBScript is not object-oriented while ASP.NET is because .NET is. You will need to make some changes in the way you approach user controls for headers, footers, and other common sections that you have used SSIs for in the past.

      Also, don’t try to recreate exactly what you have in ASP to ASP.NET. This will only frustrate you. More or less, start from scratch, using your ASP page as a guide, taking full advantage of the .NET paradigm.

Viewing 3 reply threads