form auhentication redirect to custom page

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4 I have the folowing code in the login page
<pre class="prettyprint lang-vb If objDR.Read = True Then
Dim ticket As New FormsAuthenticationTicket(1,
objDR("UserID").ToString,
DateTime.Now,
DateTime.Now.AddMinutes(30),
True,
objDR("Roles").ToString,
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, hash)
Dim strUrl As String = Request.QueryString("ReturnUrl")

If ticket.IsPersistent Then
cookie.Expires = ticket.Expiration
End If
Response.Cookies.Add(cookie)

Dim cookieLogin As HttpCookie = New HttpCookie(CommonLib.COOKIE_USERLOGIN)
cookieLogin(CommonLib.COOKIE_USERROLE) = objDR("Roles").ToString
cookieLogin(CommonLib.COOKIE_LOGINID) = objDR("LoginID").ToString
cookieLogin(CommonLib.COOKIE_USERID) = objDR("UserID").ToString

FormsAuthentication.SetAuthCookie(objDR("LoginID").ToString, False)

If strUrl Is Nothing Then
strUrl = "/"
End If
If objDR("Roles").ToString = "Admin" Then
cookieLogin.Expires = Now.AddDays(1)
Response.Cookies.Add(cookieLogin)

Response.Redirect("Admin/FileImport.aspx")

ElseIf objDR("Roles").ToString = "Student" Then
cookieLogin.Expires = Now.AddDays(1)
Response.Cookies.Add(cookieLogin)
Response.Redirect("Student/PersonalInfo.aspx")

Else
Response.Redirect("Lecturer/ConsultationMaintenance.aspx")
cookieLogin.Expires = Now.AddDays(1)
Response.Cookies.Add(cookieLogin)

End If
Else
lblMsg.Text = "Login id and Password incorrect"
txtLoginID.Focus()
End If[/code]
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4 Then I also have the following code in global.asax
<pre class="prettyprint Protected Sub Application_AuthenticateRequest(sender As Object, e As System.EventArgs)
If HttpContext.Current.User IsNot Nothing Then
see if this user is authenticated, any authenticated cookie (ticket) exists for this user
If HttpContext.Current.User.Identity.IsAuthenticated Then
see if the authentication is done using FormsAuthentication

If TypeOf HttpContext.Current.User.Identity Is FormsIdentity Then
Get the roles stored for this request from the ticket
get the identity of the user

Dim identity As FormsIdentity = HttpContext.Current.User.Identity
get the forms authetication ticket of the user
Dim ticket As FormsAuthenticationTicket = identity.Ticket
get the roles stored as UserData into the ticket
Dim roles As String() = ticket.UserData.Split(",")
HttpContext.Current.User = New System.Security.Principal.GenericPrincipal(identity, roles)
End If
End If
End If
End Sub[/code]
<br/>
<p style="margin-bottom:15px; padding-right:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; font-size:13px; vertical-align:baseline; background-color:#f0f3f4; color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif
When i login as a student, it cannpt response to redirect the page i want to ,
<p style="margin-bottom:15px; padding-right:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; font-size:13px; vertical-align:baseline; background-color:#f0f3f4; color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif
and login as a lecturer also has the same case, cannot redirect the page i want.
<p style="margin-bottom:15px; padding-right:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; font-size:13px; vertical-align:baseline; background-color:#f0f3f4; color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif
I really not idea what is the problem, can anyone help me
<br/>
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4
<span style="color:#222222; font-family:Segoe UI,Tahoma,Arial,Helvetica,sans-serif; font-size:13px; background-color:#f0f3f4

View the full article
 
Back
Top