macros14
asked on
Forms Authentication without redirect
I have authentication (username and password textboxes) on my homepage. The user enters there username and password, and everything works correctly when I have this statement after I build my authentication ticket and cookie.
response.Redirect(FormsAut henticatio n.GetRedir ectUrl(sUs erName, False), False)
But since this isn't a login page but rather a homepage, I don't want to redirect. If I comment out the response.redirect, and then ask If User.Identity.IsAuthentica ted it says the user isn't. Is there a way to get around having to redirect to get the user added to the authentication list??
Here is more of my authentication method
' Initialize FormsAuthentication (reads the configuration and gets
' the cookie values and encryption keys for the given application)
FormsAuthentication.Initia lize()
If cbKeepLoggedIn.Checked Then
bKeepLoggedIn = True
dLogoutDate = Now.AddDays(8)
End If
' Create a new ticket used for authentication
Dim Ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket( 1, sUserName, _
Now, dLogoutDate, bKeepLoggedIn, dt.Rows(0)("ROLE_CD").ToSt ring, FormsAuthentication.FormsC ookiePath)
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encryp t(Ticket)
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentica tion.Forms CookieName , hash)
If (Ticket.IsPersistent) Then
cookie.Expires = Ticket.Expiration
End If
' Add the cookie to the list for outbound response
response.Cookies.Add(cooki e)
'response.Redirect(FormsAu thenticati on.GetRedi rectUrl(sU serName, False), False)
response.Redirect(FormsAut
But since this isn't a login page but rather a homepage, I don't want to redirect. If I comment out the response.redirect, and then ask If User.Identity.IsAuthentica
Here is more of my authentication method
' Initialize FormsAuthentication (reads the configuration and gets
' the cookie values and encryption keys for the given application)
FormsAuthentication.Initia
If cbKeepLoggedIn.Checked Then
bKeepLoggedIn = True
dLogoutDate = Now.AddDays(8)
End If
' Create a new ticket used for authentication
Dim Ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(
Now, dLogoutDate, bKeepLoggedIn, dt.Rows(0)("ROLE_CD").ToSt
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encryp
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentica
If (Ticket.IsPersistent) Then
cookie.Expires = Ticket.Expiration
End If
' Add the cookie to the list for outbound response
response.Cookies.Add(cooki
'response.Redirect(FormsAu
ASKER
Doesn't work, I do like you say
FormsAuthentication.Initia lize()
If cbKeepLoggedIn.Checked Then
bKeepLoggedIn = True
dLogoutDate = Now.AddDays(8)
End If
' Create a new ticket used for authentication
Dim Ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket( 1, sUserName, _
Now, dLogoutDate, bKeepLoggedIn, dt.Rows(0)("ROLE_CD").ToSt ring, FormsAuthentication.FormsC ookiePath)
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encryp t(Ticket)
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentica tion.Forms CookieName , hash)
If (Ticket.IsPersistent) Then
cookie.Expires = Ticket.Expiration
End If
' Add the cookie to the list for outbound response
response.Cookies.Add(cooki e)
Dim sURL As String = FormsAuthentication.GetRed irectUrl(s UserName, False)
The next thing I do is
If User.Identity.IsAuthentica ted Then
BuildAuthenticatedBox()
End If
but it won't make it into the if statement because it says the isAuthenticated=false
FormsAuthentication.Initia
If cbKeepLoggedIn.Checked Then
bKeepLoggedIn = True
dLogoutDate = Now.AddDays(8)
End If
' Create a new ticket used for authentication
Dim Ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(
Now, dLogoutDate, bKeepLoggedIn, dt.Rows(0)("ROLE_CD").ToSt
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encryp
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentica
If (Ticket.IsPersistent) Then
cookie.Expires = Ticket.Expiration
End If
' Add the cookie to the list for outbound response
response.Cookies.Add(cooki
Dim sURL As String = FormsAuthentication.GetRed
The next thing I do is
If User.Identity.IsAuthentica
BuildAuthenticatedBox()
End If
but it won't make it into the if statement because it says the isAuthenticated=false
ASKER
I have found this formsauthentication.setaut hcookie()
Which is suppose to do the same thing as redirect(authenticate the user) but it won't accept my created cookie but rather wants to build a new cookie which isn't what I want.
Which is suppose to do the same thing as redirect(authenticate the user) but it won't accept my created cookie but rather wants to build a new cookie which isn't what I want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have done this in one of my projects, it leaves the user logged in, but doesn't take them anywhere:
URL = FormsAuthentication.GetRed
I'd recommend letting the user know they've logged in, but it should be as simple as that.
Cheers,
mcg