Page Redirecting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • damiensawyer@yahoo.com.au

    Page Redirecting

    Hi,

    I'm trying to do something in global.asax that I would have thought to
    be quite simple. Basically, any request at all should get sent to
    another page. I actually got the code below from a book. For some
    reason, it's not working.

    Can someone please tell me what I'm doing wrong?

    Thanks in advance,


    Damien

    protected void Application_Beg inRequest(objec t sender,
    EventArgs e)
    {
    // this causes a "redirect loop"
    Response.Redire ct(Request.Appl icationPath + "/Forms/
    LoginPage.aspx" );

    // This just "doesn't work" - standard page loads.
    Context.Rewrite Path(Request.Ap plicationPath + "/Forms/
    LoginPage.aspx" );
    }
  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Page Redirecting

    damiensawyer@ya hoo.com.au wrote:
    Hi,
    >
    I'm trying to do something in global.asax that I would have thought to
    be quite simple. Basically, any request at all should get sent to
    another page. I actually got the code below from a book. For some
    reason, it's not working.
    >
    Can someone please tell me what I'm doing wrong?
    >
    Thanks in advance,
    >
    >
    Damien
    >
    protected void Application_Beg inRequest(objec t sender,
    EventArgs e)
    {
    // this causes a "redirect loop"
    Response.Redire ct(Request.Appl icationPath + "/Forms/
    LoginPage.aspx" );
    You have to check if it's the login page that is requested or not. Now
    you are redirecting every request, even the ones that you are causing by
    redirecting to the login page.
    // This just "doesn't work" - standard page loads.
    Context.Rewrite Path(Request.Ap plicationPath + "/Forms/
    LoginPage.aspx" );
    }
    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • =?Utf-8?B?QldD?=

      #3
      RE: Page Redirecting

      Your "redirect loop" is caused because you are not checking whether the
      currently executing page is "LoginPage.aspx "

      So even a successful redirect to LoginPage.aspx then redirects to
      LoginPage.aspx, and the cycle continues.

      I suggest checking the currently loaded page (Request.Url should help).

      Otherwise, it might be worth looking at using a built in Authentication
      provider like FormsAuthentica tion or similar to provide this redirect to
      login functionality.

      Good luck,
      BWC

      "damiensawyer@y ahoo.com.au" wrote:
      Hi,
      >
      I'm trying to do something in global.asax that I would have thought to
      be quite simple. Basically, any request at all should get sent to
      another page. I actually got the code below from a book. For some
      reason, it's not working.
      >
      Can someone please tell me what I'm doing wrong?
      >
      Thanks in advance,
      >
      >
      Damien
      >
      protected void Application_Beg inRequest(objec t sender,
      EventArgs e)
      {
      // this causes a "redirect loop"
      Response.Redire ct(Request.Appl icationPath + "/Forms/
      LoginPage.aspx" );
      >
      // This just "doesn't work" - standard page loads.
      Context.Rewrite Path(Request.Ap plicationPath + "/Forms/
      LoginPage.aspx" );
      }
      >

      Comment

      • Mark Rae [MVP]

        #4
        Re: Page Redirecting

        <damiensawyer@y ahoo.com.auwrot e in message
        news:8d29d3c1-bbfb-4778-a591-3bf78d31995a@s3 3g2000pri.googl egroups.com...
        Can someone please tell me what I'm doing wrong?
        This has already been answered.

        However, even if you check whether the current Request.Url contains
        "LoginPage.aspx ", what then...?

        As it stands currently, your users will never be able to proceed any further
        than the login page...


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • damiensawyer@yahoo.com.au

          #5
          Re: Page Redirecting

          >As it stands currently, your users will never be able to proceed any further than the login page...

          Correct. Sorry - this wasn't the best example. I'm just 'playing
          around' to test the functionality.

          Out of interest, I got the response.redire ct working by ommitting
          calls to the login page, however, I can't get the context.rewrite to
          happen. Googling around, I found a few posts of people having trouble
          with it... none of them which seemed to have answers.

          Thanks very much for everyone's help :-)

          On Jun 24, 7:28 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
          <damiensaw...@y ahoo.com.auwrot e in message
          >
          news:8d29d3c1-bbfb-4778-a591-3bf78d31995a@s3 3g2000pri.googl egroups.com...
          >
          Can someone please tell me what I'm doing wrong?
          >
          This has already been answered.
          >
          However, even if you check whether the current Request.Url contains
          "LoginPage.aspx ", what then...?
          >
          As it stands currently, your users will never be able to proceed any further
          than the login page...
          >
          --
          Mark Rae
          ASP.NET MVPhttp://www.markrae.net

          Comment

          Working...