Re: Role Based Forms Authentication Help!
From: John Saunders (john.saunders@surfcontrol.com)
Date: 11/22/02
- Next message: Lanky: "Re: Role Based Forms Authentication Help!"
- Previous message: kris: "Role Based Forms Authentication Help!"
- In reply to: Lanky: "Re: Role Based Forms Authentication Help!"
- Next in thread: Lanky: "Re: Role Based Forms Authentication Help!"
- Reply: Lanky: "Re: Role Based Forms Authentication Help!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "John Saunders" <john.saunders@surfcontrol.com> Date: Thu, 21 Nov 2002 18:52:07 -0500
Try:
If TypeOf Context.User.Identity Is FormsIdentity Then
Also, the FormsIdentity constructor takes a FormsAuthenticationTicket as its
sole parameter, not an IIdentity.
Good Luck,
John Saunders
Internet Engineer
John.Saunders@surfcontrol.com
"Lanky" <lanky_tx@NOSPAMyahoo.com> wrote in message
news:zAbD9.402$TO6.356403338@newssvr11.news.prodigy.com...
> I'm Sorry yes.
>
> On the If statement If HttpContext.Current.User.Identity Is
> System.Web.Security.FormsIdentity Then 'This line errors
> The if statement portion of System.Web.Security.FormsIdentity has an error
> of 'FormsIdentidy' is atype and cannot be used as an expression. If I
> comment that out and then run it again the next line Dim id As
> System.Web.Security.FormsIdentity = New
> System.Web.Security.FormsIdentity(HttpContext.Current.User.Identity) an
> error is being generated during runtime.
>
> Specified cast is not valid
>
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.InvalidCastException: Specified cast is not
valid.
>
> Source Error:
>
>
> Line 54:
> Line 55:
> Line 56: Dim id As FormsIdentity = New
> FormsIdentity(HttpContext.Current.User.Identity) 'Error at this line
> Line 57: Dim ticket As FormsAuthenticationTicket =
id.Ticket
> Line 58: Dim strUser As String = ticket.UserData
>
>
> Any thoughts?
>
> Regards,
>
> Lanky
>
> "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> news:#HZoFFZkCHA.1428@tkmsftngp11...
> > Care to share the error?
> >
> > John Saunders
> >
> >
> > "Lanky" <lanky_tx@NOSPAMyahoo.com> wrote in message
> > news:UD7D9.3599$Od5.1463061665@newssvr12.news.prodigy.com...
> > > Hi All,
> > >
> > > I am new at this so please bare with me. I am trying to get role
based
> > > forms authentication to work and I am having problems with 2 lines of
> code
> > > at least. It won't recogize what I pass in.
> > >
> > > I click on the Login button and that all works but when the
> > > Application_Authenticaterequest method fires and the Current User has
> > > successfully logged in it fails on those 2 lines. I marked the lines
> > where
> > > I am having a problem.
> > >
> > > Could someone help?
> > >
> > > TIA, Lanky
> > >
> > > 'This Is in my Global.assx Application_Authenticaterequest
> > >
> > > If Not HttpContext.Current.User Is Nothing Then
> > >
> > > If HttpContext.Current.User.Identity.IsAuthenticated = True Then
> > >
> > > If HttpContext.Current.User.Identity Is
> System.Web.Security.FormsIdentity
> > > Then 'This line errors
> > >
> > > Dim id As System.Web.Security.FormsIdentity = New
> > > System.Web.Security.FormsIdentity(HttpContext.Current.User.Identity)
> > ''This
> > > line errors
> > >
> > > Dim ticket As System.Web.Security.FormsAuthenticationTicket =
id.Ticket
> > >
> > > Dim strUser As String = ticket.UserData
> > >
> > > Dim roles As String() = strUser.Split(",")
> > >
> > > HttpContext.Current.User = New GenericPrincipal(id, roles)
> > >
> > > End If
> > >
> > > End If
> > >
> > > End If
> > >
> > >
> > >
> > > 'This is in my Login Button Onclick Event
> > >
> > > Protected Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles btnLogin.Click
> > >
> > > FormsAuthentication.Initialize()
> > >
> > > Dim strReturnURL As String
> > >
> > > Dim strRole As String
> > >
> > > Dim objSWF As SWFStore.SWFAuthentication = New
> > SWFStore.SWFAuthentication()
> > >
> > > 'The objSWF.GetRole Method just retrives the role for a user and their
> > > password from a DB table
> > >
> > > Dim objRD As SqlClient.SqlDataReader =
> > > objSWF.GetRole(txtUsername.Value.ToString(),
> txtPassword.Value.ToString())
> > >
> > > If objRD.Read = True Then
> > >
> > > strRole = objRD.GetString(0).ToUpper()
> > >
> > > Dim ticket As FormsAuthenticationTicket = New
> FormsAuthenticationTicket(1,
> > > txtUsername.Value.ToString, DateTime.Now, DateTime.Now.AddHours(2),
> True,
> > > strRole, FormsAuthentication.FormsCookiePath)
> > >
> > > Dim strHash As String = FormsAuthentication.Encrypt(ticket)
> > >
> > > Dim ckCookie As HttpCookie = New
> > > HttpCookie(FormsAuthentication.FormsCookieName, strHash)
> > >
> > > Response.Cookies.Add(ckCookie)
> > >
> > > Select Case strRole
> > >
> > > Case "ADMINROLE"
> > >
> > > If Request.QueryString("ReturnUrl") <> "" Then
> > >
> > > strReturnURL = Request.QueryString("ReturnUrl")
> > >
> > > Else
> > >
> > > strReturnURL = "ADMIN/Admin_Home.aspx"
> > >
> > > End If
> > >
> > > 'Case "OTHER"
> > >
> > > 'Case "OtherROle"
> > >
> > > 'Case "OtherROle"
> > >
> > > Case Else
> > >
> > >
> > >
> > > strReturnURL = "/"
> > >
> > > End Select
> > >
> > > Response.Redirect(strReturnURL, False)
> > >
> > > Else
> > >
> > > lblErrorLabel.Text = "Username / Password is incorrect to access this
> > > resource. Please try again."
> > >
> > > lblErrorLabel.Visible = True
> > >
> > > End If
> > >
> > > End Sub
> > >
> > >
> > >
> > >
> >
> >
>
>
- Next message: Lanky: "Re: Role Based Forms Authentication Help!"
- Previous message: kris: "Role Based Forms Authentication Help!"
- In reply to: Lanky: "Re: Role Based Forms Authentication Help!"
- Next in thread: Lanky: "Re: Role Based Forms Authentication Help!"
- Reply: Lanky: "Re: Role Based Forms Authentication Help!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]