Wednesday, December 24, 2003

 

311495 - HOW TO: Implement Role-Based Security with Forms-Based Authentication in Your ASP.NET Application by Using Visual C# .NET

Assign the Roles to the Authenticating User:
===
public void Application_AuthenticateRequest
{
...
String[] myRoles = new String[2];
myRoles[0] = "Manager";
myRoles[1] = "Admin";
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id,myRoles);
...
}
===


Check the User Roles
===
public void Page_Load() {
if (User.IsInRole("Admin")){
Response.Write ("You are an Administrator");}
else {
Response.Write ("You do not have any role assigned");}
}
===

311495 - HOW TO: Implement Role-Based Security with Forms-Based Authentication in Your ASP.NET Application by Using Visual C# .NET

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?