Forms Authentication

B

Brad Farrell

If anyone can help on this, I would appreciate it.

Got a website and I'm trying to protect a portion of it under a subfolder
called "Protected"

In my web.config file I have the following for the authorization tag.
Authentication is set to forms and pointing to my login.aspx page.

<location path="Protected">

<system.web>

<authorization>

<allow roles="admin"/>

<allow roles="Admin"/>

<deny users="*"/>

</authorization>

</system.web>

</location>

In my login.aspx.cs file, I match the user credentials up with the database
and run the following:



FormsAuthentication.Initialize();

String strRole = AssignRoles(customerId); "Returns my admin role"

FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1,customerId,

DateTime.Now,DateTime.Now.AddMinutes(20),RememberLogin.Checked,strRole,

FormsAuthentication.FormsCookiePath);

Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,

FormsAuthentication.Encrypt(fat)));

Response.Redirect(FormsAuthentication.GetRedirectUrl(customerId,
RememberLogin.Checked));



In my header portion, I am trying to hide/show a menu option using the
following:

Admin.Visible = Page.User.IsInRole("admin");



The role comes back from the database as admin, but the
Page.User.IsInRole("admin") is returning a false result. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top