Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Role-based security in C#

Status
Not open for further replies.

olapol

Programmer
Feb 13, 2002
5
PL
I am trying to make a role-based security in C# Web Application. And I am afraid that it not work in C# because of some VS.NET error!

I cover an OnAuthenticate event in global ascx with code:

HttpApplication app = (HttpApplication) sender;
if (app.Request.IsAuthenticated && app.User.Identity is FormsIdentity)

{
FormsIdentity identity = (FormsIdentity) app.User.Identity;
if (identity.Name == "1")
app.Context.User = new GenericPrincipal (identity, new string[] { "serwis" });
}

I also write a login page, with function:

GUITelemetria.DataBase.UserDB m_userDB = new GUITelemetria.DataBase.UserDB();
String userID = m_userDB.Login(txName.Text,txPassword.Text);
if(userID != null)
{
Session.Add("userID",userID);

FormsAuthentication.SetAuthCookie(userID, false);
FormsAuthentication.RedirectFromLoginPage(userID, false);
}
else
lResult.Text = "Error";
}

Finally, I put into web.config:

<authentication mode=&quot;Forms&quot; >
<forms name=&quot;GUITelemetria&quot; loginUrl=&quot;login.aspx&quot; protection=&quot;All&quot; timeout=&quot;240&quot;/>
</authentication>

<authorization>
<deny users=&quot;?&quot;/>
</authorization>

<location path=&quot;tank.aspx&quot;>
<system.web>
<authorization>
<allow roles=&quot;serwis&quot;/>
<deny users=&quot;*&quot;/>
</authorization>
</system.web>
</location>

And it doesn't work... When I am debug my program, I am find that app.Request.IsAuthenticated doesn't remember settings. After authentication it is still false!

I will be really grateful for any help.

Alexandra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top