Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > RedirectFromLoginPage not redirecting

Reply
Thread Tools

RedirectFromLoginPage not redirecting

 
 
sean
Guest
Posts: n/a
 
      05-10-2004
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)

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



 
Reply With Quote
 
 
 
 
Janaka
Guest
Posts: n/a
 
      05-10-2004
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" <> wrote in message
news:a88e01c43688$08aca1c0$...
> 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)
>
> .................................................. .......
>
>
>



 
Reply With Quote
 
 
 
 
sean
Guest
Posts: n/a
 
      05-10-2004
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" <> wrote in

message
>news:a88e01c43688$08aca1c0$...
>> 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)
>>
>> .................................................. ......

..
>>
>>
>>

>
>
>.
>

 
Reply With Quote
 
Janaka
Guest
Posts: n/a
 
      05-10-2004
sean

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

Janaka

"sean" <> wrote in message
news:ace301c43699$b50052d0$...
> 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" <> wrote in

> message
> >news:a88e01c43688$08aca1c0$...
> >> 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)
> >>
> >> .................................................. ......

> .
> >>
> >>
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
sean
Guest
Posts: n/a
 
      05-10-2004
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" <> wrote in

message
>news:ace301c43699$b50052d0$...
>> 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" <> wrote in

>> message
>> >news:a88e01c43688$08aca1c0$...
>> >> 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)
>> >>
>> >> .................................................. ...

....
>> .
>> >>
>> >>
>> >>
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
carol
Guest
Posts: n/a
 
      05-21-2004
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
 
Reply With Quote
 
carol
Guest
Posts: n/a
 
      05-21-2004
Another possible solution may be found in this link re: your threadabort error:
http://support.microsoft.com/default...kb;en-us;31262

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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FormsAuthentication.RedirectFromLoginPage is not redirecting to the correct page. Jeremy Chapman ASP .Net 1 09-21-2005 09:39 PM
Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage Tim_Mac ASP .Net Security 0 05-11-2005 12:31 PM
RedirectFromLoginPage not redirecting to RedirectUrl jjjooooohhnnn@mail.com ASP .Net 4 03-01-2005 06:02 AM
FormsAuthentication.RedirectFromLoginPage is not passed fully qualified url Jacob Crossley ASP .Net 0 04-02-2004 04:04 PM
System.Web.Security.FormsAuthentication.RedirectFromLoginPage is not working.. TaeHo Yoo ASP .Net 1 07-09-2003 07:46 AM



Advertisments
 



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