c# : asp.net : problem wit session and server.transfer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishalgupta
    New Member
    • Jun 2007
    • 47

    c# : asp.net : problem wit session and server.transfer

    i have

    void Application_Err or(object sender, EventArgs e)
    {
    Server.Transfer ("default.aspx" );
    }
    in global.asax

    now when i use any state bags like Session["sno"] = "new";
    whenever the user clicks on link to a page that does not exist on the server, Application_Err or() executes but Server.Transfer does not and it shows that the page cannot be found and does not transfer to default.aspx.
    why is Server.Transfer not getting executed ??
  • kunal pawar
    Contributor
    • Oct 2007
    • 297

    #2
    rather than to use server.transfer

    add following code in ur web.config

    <customErrors defaultRedirect ="default.as px" mode="On">
    </customErrors>

    Comment

    • vishalgupta
      New Member
      • Jun 2007
      • 47

      #3
      this wont work as i have to display the url that the user has clicked
      i.e http://localhost:1126/N/default5.aspx

      but customerror displays

      in the address bar

      is there some other way to do this??

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        I think that you may benefit from this overview:
        How to create custom error reporting pages in ASP.NET by using Visual C# .NET

        I'm not sure what you are hoping to achieve, an application error is unlikely to display the default page (hence the need for error handling).

        Comment

        • vishalgupta
          New Member
          • Jun 2007
          • 47

          #5
          i am sry but the above link doesnt slove my problem

          i have a link on my page which points to default5.aspx
          but as default5.aspx does not exist on the server the Application_Err or is invoked :
          void Application_Err or(object sender, EventArgs e)
          {
          Server.Transfer ("default.aspx" );
          }
          which tansfers the user to default.aspx but shows default5.aspx in the address bar.
          now if i use state bags like Session["sno"] = "new"; itshows the error that default.aspx is not found on the server.

          if use customerrors in web.config then it does redirect to default.aspx but shows some asp error url in the address bar.
          but i want to display default5.aspx in the address bar
          but how??

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by vishalgupta
            i am sry but the above link doesnt slove my problem

            i have a link on my page which points to default5.aspx
            but as default5.aspx does not exist on the server the Application_Err or is invoked :
            void Application_Err or(object sender, EventArgs e)
            {
            Server.Transfer ("default.aspx" );
            }
            which tansfers the user to default.aspx but shows default5.aspx in the address bar.
            now if i use state bags like Session["sno"] = "new"; itshows the error that default.aspx is not found on the server.

            if use customerrors in web.config then it does redirect to default.aspx but shows some asp error url in the address bar.
            but i want to display default5.aspx in the address bar
            but how??
            When you use Server.Transfer the requested URL is displayed in the browser.
            The reason is because the Server changes what ASPX page to display....

            For example:
            The user requests the requestedAspxPa ge.aspx :
            The requestedAspxPa ge.aspx doesn't exist, so you call Server.Transfer (anotherAspxPag e.aspx)
            The Server uses anotherAspxPage .aspx instead of the requestedAspxPa ge.aspx.

            Since the server handles this, the URL in the web browser is not changed.

            Now, if you use Response.Redire ct(anotherAspxP age.aspx), the server returns an HTML code indicating to the browser that it should request anotherAspxPage . The URL is changed and the browser requests the "anotherAspxPag e" instead of the requestedAspxPa ge.

            I would use Response.Redire ct for "Page Not Found" (404) errors...becaus e if the url still points to a page that doesn't exist, the next time the user does a postback another error will occur again.

            You can Rewrite the URL if you want...
            See URL rewriting in ASP.NET for more information on the topic.

            -Frinny

            Comment

            Working...