raybiss
07-04-2009, 03:57 AM
Hi,
I'm migrating an existing web site and I'm having problems with IsInRole always returning false.
Page.User.IsInRole("admin") ' or any other role
Page.User.Identity.Name works fine, returning the user name.
The FormsAuthenticationTicket is set with code that looks like this.
...
FormsAuthentication.Initialize()
...
Dim ticket As New FormsAuthenticationTicket(1, _
sUserName, _
DateTime.Now, _
DateTime.Now.AddDays(15), _
bPersists, sRoles, _
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As New HttpCookie(FormsAuthentication.FormsCookieName, hash)
If ticket.IsPersistent Then cookie.Expires = DateTime.Now.AddDays(15)
...
This code works on my dev machine, on at least one other web site and was working fine at my last provider.
Any idea on what could be wrong?
If someone is using FormsAuthentication like the above, could you show me how your web.config file is setup?
Otherwise, how should I authenticate users? The site was upgraded from ASP.NET 1.1. I'm using an Access database at the moment.
TIA,
Raymond
I'm migrating an existing web site and I'm having problems with IsInRole always returning false.
Page.User.IsInRole("admin") ' or any other role
Page.User.Identity.Name works fine, returning the user name.
The FormsAuthenticationTicket is set with code that looks like this.
...
FormsAuthentication.Initialize()
...
Dim ticket As New FormsAuthenticationTicket(1, _
sUserName, _
DateTime.Now, _
DateTime.Now.AddDays(15), _
bPersists, sRoles, _
FormsAuthentication.FormsCookiePath)
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As New HttpCookie(FormsAuthentication.FormsCookieName, hash)
If ticket.IsPersistent Then cookie.Expires = DateTime.Now.AddDays(15)
...
This code works on my dev machine, on at least one other web site and was working fine at my last provider.
Any idea on what could be wrong?
If someone is using FormsAuthentication like the above, could you show me how your web.config file is setup?
Otherwise, how should I authenticate users? The site was upgraded from ASP.NET 1.1. I'm using an Access database at the moment.
TIA,
Raymond