RedirectFromLoginPage not redirecting

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default RedirectFromLoginPage not redirecting

    I'm attempting to use Forms/Roles based authentication and
    authorization. A subdirectory's web.config allows only
    "Admin" roles and it does kick browsers to a login page.
    However...when supplying proper credentials to the login
    page I'm never actually redirected to the page in the
    protected subdirectory. I've stepped through the code in
    the debugger and I can see the connection to the db open
    and the names of the roles getting fed to a cookie all just
    fine but at the last the redirect never happens. There's a
    blink (postback I'm assuming) and I stay at the login page.

    Any help greatly appreciated. Code to follow..
    .................................................. ........
    web.config of protected directory:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.web>
    <authorization>
    <allow roles="Administrator" />
    <deny users="*" />
    </authorization>
    </system.web>
    </configuration>
    .................................................. ........

    .................................................. ........
    code in login.aspx onClick event handler:

    Dim cookieRoles As New StringBuilder

    While reader.Read()
    cookieRoles.Append(reader("Role").
    ToString())
    cookieRoles.Append(".")
    End While

    ' Save the Roles in a client Cookie for
    future requests
    Dim RoleCookie As HttpCookie = New
    HttpCookie("Roles")

    RoleCookie.Value = cookieRoles.ToString()

    Response.Cookies.Add(RoleCookie)

    FormsAuthentication.
    RedirectFromLoginPage(UserName.Text, PersistCookie.Checked)

    .................................................. ........



    sean Guest

  2. Similar Questions and Discussions

    1. Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage
      hi, i've read a lot of posts here about people who ran into problems using forms authentication, and the RedirectFromLoginPage() method, which...
    2. FormsAuthentication.RedirectFromLoginPage And Frames
      Hi! I have a page called Login.aspx that handles login (takes username, pass and compares to a database). If the user is authenticated,...
    3. RedirectFromLoginPage, use location.replace instead?
      Hey- I have a web app I'm writing where I cannot allow there to be any pages loaded into the history during the course of going from page to...
    4. RedirectFromLoginPage fails
      I am trying to implement the classic ASP.NET FormsAuthentication model for a website. The behavior of the website is normal until the login.aspx...
    5. MobileFormsAuthentication.RedirectFromLoginPage
      I use MobileFormsAuthentication.RedirectFromLoginPage. everything works fine except that it tells the user that the current page, which is the...
  3. #2

    Default Re: RedirectFromLoginPage not redirecting

    If your wanting to use role-based authentication then you need to get the
    role information into the forms authentication ticket.
    Don't worry about making another cookie for your roles. Just redirect from
    login as you've done.
    In your global.asax try the following:

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)

    {

    if (Request.IsAuthenticated)

    {

    string authName = Context.User.Identity.Name;

    // Get the role to store

    string[] roles = cookieRoles.Split(','); // this can be your own
    implementation

    // Add a principal

    GenericIdentity thisIdentity = new GenericIdentity(authName);


    Context.User = new GenericPrincipal(thisIdentity, roles);

    }

    }


    "sean" <anonymous@discussions.microsoft.com> wrote in message
    news:a88e01c43688$08aca1c0$a401280a@phx.gbl...
    > I'm attempting to use Forms/Roles based authentication and
    > authorization. A subdirectory's web.config allows only
    > "Admin" roles and it does kick browsers to a login page.
    > However...when supplying proper credentials to the login
    > page I'm never actually redirected to the page in the
    > protected subdirectory. I've stepped through the code in
    > the debugger and I can see the connection to the db open
    > and the names of the roles getting fed to a cookie all just
    > fine but at the last the redirect never happens. There's a
    > blink (postback I'm assuming) and I stay at the login page.
    >
    > Any help greatly appreciated. Code to follow..
    > .................................................. .......
    > web.config of protected directory:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <configuration>
    > <system.web>
    > <authorization>
    > <allow roles="Administrator" />
    > <deny users="*" />
    > </authorization>
    > </system.web>
    > </configuration>
    > .................................................. .......
    >
    > .................................................. .......
    > code in login.aspx onClick event handler:
    >
    > Dim cookieRoles As New StringBuilder
    >
    > While reader.Read()
    > cookieRoles.Append(reader("Role").
    > ToString())
    > cookieRoles.Append(".")
    > End While
    >
    > ' Save the Roles in a client Cookie for
    > future requests
    > Dim RoleCookie As HttpCookie = New
    > HttpCookie("Roles")
    >
    > RoleCookie.Value = cookieRoles.ToString()
    >
    > Response.Cookies.Add(RoleCookie)
    >
    > FormsAuthentication.
    > RedirectFromLoginPage(UserName.Text, PersistCookie.Checked)
    >
    > .................................................. .......
    >
    >
    >

    Janaka Guest

  4. #3

    Default Re: RedirectFromLoginPage not redirecting

    Should have added..I have the following in my global.asax.
    vb and still no redirect:

    Sub Application_AuthenticateRequest(ByVal sender As Object,
    ByVal e As EventArgs)
    Dim context As HttpContext = HttpContext.Current
    If Not context.User Is Nothing AndAlso context.
    User.Identity.IsAuthenticated Then
    Dim userIdentity As GenericIdentity = New
    GenericIdentity(context.User.Identity.Name, "Forms")
    Dim userPrincipal As GenericPrincipal = New
    GenericPrincipal(userIdentity, context.Request.
    Cookies("Roles").Value.Split("."))
    context.User = userPrincipal
    End If
    End Sub

    thanks,
    s~
    >-----Original Message-----
    >If your wanting to use role-based authentication then you
    need to get the
    >role information into the forms authentication ticket.
    >Don't worry about making another cookie for your roles.
    Just redirect from
    >login as you've done.
    >In your global.asax try the following:
    >
    >protected void Application_AuthenticateRequest(Object
    sender, EventArgs e)
    >
    >{
    >
    >if (Request.IsAuthenticated)
    >
    >{
    >
    > string authName = Context.User.Identity.Name;
    >
    > // Get the role to store
    >
    > string[] roles = cookieRoles.Split(','); // this
    can be your own
    >implementation
    >
    > // Add a principal
    >
    > GenericIdentity thisIdentity = new
    GenericIdentity(authName);
    >
    >
    > Context.User = new GenericPrincipal(thisIdentity,
    roles);
    >
    >}
    >
    >}
    >
    >
    >"sean" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:a88e01c43688$08aca1c0$a401280a@phx.gbl...
    >> I'm attempting to use Forms/Roles based authentication
    and
    >> authorization. A subdirectory's web.config allows only
    >> "Admin" roles and it does kick browsers to a login page.
    >> However...when supplying proper credentials to the login
    >> page I'm never actually redirected to the page in the
    >> protected subdirectory. I've stepped through the code in
    >> the debugger and I can see the connection to the db open
    >> and the names of the roles getting fed to a cookie all
    just
    >> fine but at the last the redirect never happens. There's
    a
    >> blink (postback I'm assuming) and I stay at the login
    page.
    >>
    >> Any help greatly appreciated. Code to follow..
    >> .................................................. ......
    ..
    >> web.config of protected directory:
    >>
    >> <?xml version="1.0" encoding="utf-8" ?>
    >> <configuration>
    >> <system.web>
    >> <authorization>
    >> <allow roles="Administrator" />
    >> <deny users="*" />
    >> </authorization>
    >> </system.web>
    >> </configuration>
    >> .................................................. ......
    ..
    >>
    >> .................................................. ......
    ..
    >> code in login.aspx onClick event handler:
    >>
    >> Dim cookieRoles As New StringBuilder
    >>
    >> While reader.Read()
    >> cookieRoles.Append(reader("Role").
    >> ToString())
    >> cookieRoles.Append(".")
    >> End While
    >>
    >> ' Save the Roles in a client Cookie for
    >> future requests
    >> Dim RoleCookie As HttpCookie = New
    >> HttpCookie("Roles")
    >>
    >> RoleCookie.Value = cookieRoles.ToString()
    >>
    >> Response.Cookies.Add(RoleCookie)
    >>
    >> FormsAuthentication.
    >> RedirectFromLoginPage(UserName.Text, PersistCookie.
    Checked)
    >>
    >> .................................................. ......
    ..
    >>
    >>
    >>
    >
    >
    >.
    >
    sean Guest

  5. #4

    Default Re: RedirectFromLoginPage not redirecting

    sean

    try using the FormsAuthentication.GetAuthCookie() method instead and then
    doing a manual Response.Redirect()

    Janaka

    "sean" <anonymous@discussions.microsoft.com> wrote in message
    news:ace301c43699$b50052d0$a101280a@phx.gbl...
    > Should have added..I have the following in my global.asax.
    > vb and still no redirect:
    >
    > Sub Application_AuthenticateRequest(ByVal sender As Object,
    > ByVal e As EventArgs)
    > Dim context As HttpContext = HttpContext.Current
    > If Not context.User Is Nothing AndAlso context.
    > User.Identity.IsAuthenticated Then
    > Dim userIdentity As GenericIdentity = New
    > GenericIdentity(context.User.Identity.Name, "Forms")
    > Dim userPrincipal As GenericPrincipal = New
    > GenericPrincipal(userIdentity, context.Request.
    > Cookies("Roles").Value.Split("."))
    > context.User = userPrincipal
    > End If
    > End Sub
    >
    > thanks,
    > s~
    >
    > >-----Original Message-----
    > >If your wanting to use role-based authentication then you
    > need to get the
    > >role information into the forms authentication ticket.
    > >Don't worry about making another cookie for your roles.
    > Just redirect from
    > >login as you've done.
    > >In your global.asax try the following:
    > >
    > >protected void Application_AuthenticateRequest(Object
    > sender, EventArgs e)
    > >
    > >{
    > >
    > >if (Request.IsAuthenticated)
    > >
    > >{
    > >
    > > string authName = Context.User.Identity.Name;
    > >
    > > // Get the role to store
    > >
    > > string[] roles = cookieRoles.Split(','); // this
    > can be your own
    > >implementation
    > >
    > > // Add a principal
    > >
    > > GenericIdentity thisIdentity = new
    > GenericIdentity(authName);
    > >
    > >
    > > Context.User = new GenericPrincipal(thisIdentity,
    > roles);
    > >
    > >}
    > >
    > >}
    > >
    > >
    > >"sean" <anonymous@discussions.microsoft.com> wrote in
    > message
    > >news:a88e01c43688$08aca1c0$a401280a@phx.gbl...
    > >> I'm attempting to use Forms/Roles based authentication
    > and
    > >> authorization. A subdirectory's web.config allows only
    > >> "Admin" roles and it does kick browsers to a login page.
    > >> However...when supplying proper credentials to the login
    > >> page I'm never actually redirected to the page in the
    > >> protected subdirectory. I've stepped through the code in
    > >> the debugger and I can see the connection to the db open
    > >> and the names of the roles getting fed to a cookie all
    > just
    > >> fine but at the last the redirect never happens. There's
    > a
    > >> blink (postback I'm assuming) and I stay at the login
    > page.
    > >>
    > >> Any help greatly appreciated. Code to follow..
    > >> .................................................. ......
    > .
    > >> web.config of protected directory:
    > >>
    > >> <?xml version="1.0" encoding="utf-8" ?>
    > >> <configuration>
    > >> <system.web>
    > >> <authorization>
    > >> <allow roles="Administrator" />
    > >> <deny users="*" />
    > >> </authorization>
    > >> </system.web>
    > >> </configuration>
    > >> .................................................. ......
    > .
    > >>
    > >> .................................................. ......
    > .
    > >> code in login.aspx onClick event handler:
    > >>
    > >> Dim cookieRoles As New StringBuilder
    > >>
    > >> While reader.Read()
    > >> cookieRoles.Append(reader("Role").
    > >> ToString())
    > >> cookieRoles.Append(".")
    > >> End While
    > >>
    > >> ' Save the Roles in a client Cookie for
    > >> future requests
    > >> Dim RoleCookie As HttpCookie = New
    > >> HttpCookie("Roles")
    > >>
    > >> RoleCookie.Value = cookieRoles.ToString()
    > >>
    > >> Response.Cookies.Add(RoleCookie)
    > >>
    > >> FormsAuthentication.
    > >> RedirectFromLoginPage(UserName.Text, PersistCookie.
    > Checked)
    > >>
    > >> .................................................. ......
    > .
    > >>
    > >>
    > >>
    > >
    > >
    > >.
    > >

    Janaka Guest

  6. #5

    Default Re: RedirectFromLoginPage not redirecting

    On the response.redirect I get System.Threading.
    ThreadAbortException and continue to get no redirect...

    thx for the feedback Janaka
    S~


    >-----Original Message-----
    >sean
    >
    >try using the FormsAuthentication.GetAuthCookie() method
    instead and then
    >doing a manual Response.Redirect()
    >
    >Janaka
    >
    >"sean" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:ace301c43699$b50052d0$a101280a@phx.gbl...
    >> Should have added..I have the following in my global.
    asax.
    >> vb and still no redirect:
    >>
    >> Sub Application_AuthenticateRequest(ByVal sender As
    Object,
    >> ByVal e As EventArgs)
    >> Dim context As HttpContext = HttpContext.Current
    >> If Not context.User Is Nothing AndAlso context.
    >> User.Identity.IsAuthenticated Then
    >> Dim userIdentity As GenericIdentity = New
    >> GenericIdentity(context.User.Identity.Name, "Forms")
    >> Dim userPrincipal As GenericPrincipal = New
    >> GenericPrincipal(userIdentity, context.Request.
    >> Cookies("Roles").Value.Split("."))
    >> context.User = userPrincipal
    >> End If
    >> End Sub
    >>
    >> thanks,
    >> s~
    >>
    >> >-----Original Message-----
    >> >If your wanting to use role-based authentication then
    you
    >> need to get the
    >> >role information into the forms authentication ticket.
    >> >Don't worry about making another cookie for your roles.
    >> Just redirect from
    >> >login as you've done.
    >> >In your global.asax try the following:
    >> >
    >> >protected void Application_AuthenticateRequest(Object
    >> sender, EventArgs e)
    >> >
    >> >{
    >> >
    >> >if (Request.IsAuthenticated)
    >> >
    >> >{
    >> >
    >> > string authName = Context.User.Identity.Name;
    >> >
    >> > // Get the role to store
    >> >
    >> > string[] roles = cookieRoles.Split(','); // this
    >> can be your own
    >> >implementation
    >> >
    >> > // Add a principal
    >> >
    >> > GenericIdentity thisIdentity = new
    >> GenericIdentity(authName);
    >> >
    >> >
    >> > Context.User = new GenericPrincipal(thisIdentity,
    >> roles);
    >> >
    >> >}
    >> >
    >> >}
    >> >
    >> >
    >> >"sean" <anonymous@discussions.microsoft.com> wrote in
    >> message
    >> >news:a88e01c43688$08aca1c0$a401280a@phx.gbl...
    >> >> I'm attempting to use Forms/Roles based
    authentication
    >> and
    >> >> authorization. A subdirectory's web.config allows
    only
    >> >> "Admin" roles and it does kick browsers to a login
    page.
    >> >> However...when supplying proper credentials to the
    login
    >> >> page I'm never actually redirected to the page in the
    >> >> protected subdirectory. I've stepped through the code
    in
    >> >> the debugger and I can see the connection to the db
    open
    >> >> and the names of the roles getting fed to a cookie
    all
    >> just
    >> >> fine but at the last the redirect never happens.
    There's
    >> a
    >> >> blink (postback I'm assuming) and I stay at the login
    >> page.
    >> >>
    >> >> Any help greatly appreciated. Code to follow..
    >> >> .................................................. ...
    ....
    >> .
    >> >> web.config of protected directory:
    >> >>
    >> >> <?xml version="1.0" encoding="utf-8" ?>
    >> >> <configuration>
    >> >> <system.web>
    >> >> <authorization>
    >> >> <allow roles="Administrator" />
    >> >> <deny users="*" />
    >> >> </authorization>
    >> >> </system.web>
    >> >> </configuration>
    >> >> .................................................. ...
    ....
    >> .
    >> >>
    >> >> .................................................. ...
    ....
    >> .
    >> >> code in login.aspx onClick event handler:
    >> >>
    >> >> Dim cookieRoles As New StringBuilder
    >> >>
    >> >> While reader.Read()
    >> >> cookieRoles.Append(reader("Role").
    >> >> ToString())
    >> >> cookieRoles.Append(".")
    >> >> End While
    >> >>
    >> >> ' Save the Roles in a client Cookie for
    >> >> future requests
    >> >> Dim RoleCookie As HttpCookie = New
    >> >> HttpCookie("Roles")
    >> >>
    >> >> RoleCookie.Value = cookieRoles.ToString()
    >> >>
    >> >> Response.Cookies.Add(RoleCookie)
    >> >>
    >> >> FormsAuthentication.
    >> >> RedirectFromLoginPage(UserName.Text, PersistCookie.
    >> Checked)
    >> >>
    >> >> .................................................. ...
    ....
    >> .
    >> >>
    >> >>
    >> >>
    >> >
    >> >
    >> >.
    >> >
    >
    >
    >.
    >
    sean Guest

  7. #6

    Default RedirectFromLoginPage not redirecting

    I just solved the SAME problem with my site. The problem was solved after the following 3 things were corrected on the web server. There actually wasn't anything that needed to be changed with the code

    1 - make sure the server's system ennvironment variable PATH contains the path to the directory where .NET is installed.

    2 - make sure the subdirectories that contain the protected pages are not set up as applications within IIS

    3 - make sure web sharing is turned on for those same subdirectorie

    Good Luck
    - Carol
    carol Guest

  8. #7

    Default RE: RedirectFromLoginPage not redirecting

    Another possible solution may be found in this link re: your threadabort error:
    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;31262[/url]

    For what it's worth, here's my global.asax code, different from yours..

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
    'this fires each time someone hits a protected page. If they're alread
    'logged on, this routine checks their role in the cookie an
    'displays the page if they are authorized

    'find this user's cookie that was created when the user logged o
    Dim cookieName As String = FormsAuthentication.FormsCookieNam
    Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName

    If authCookie Is Nothing The
    'there's no authentication cooki
    Retur
    End I
    'extract and decrypt the authentication ticket from the forms authentication cooki
    Dim authTicket As FormsAuthenticationTicket = Nothin
    Tr
    authTicket = FormsAuthentication.Decrypt(authCookie.Value
    Catch 'unforseen erro
    Retur
    End Tr
    If authTicket Is Nothing The
    'cookie failed to decryp
    Retur
    End I
    'extract the roles from the user's cooki
    'When the ticket was created, the UserData property was assigned
    'comma delimited string of role names
    Dim roles As String() = authTicket.UserData.Split(","
    'Create an Identity objec
    Dim id As FormsIdentity = New FormsIdentity(authTicket
    'This principal will flow throughout the request
    Dim principal As GenericPrincipal = New GenericPrincipal(id, roles
    'Attach the new principal object to the current HttpContext objec
    Context.User = principa

    End Su

    good luc
    - Carol
    carol Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139