Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Roles not working

Reply
Thread Tools

Roles not working

 
 
Neils Christoffersen
Guest
Posts: n/a
 
      11-23-2004
I have a quick question about ASP.NET roles.

I have the following in in Global.asax:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
Response.Write("Request authenticated: " + (Request.IsAuthenticated ? "yes"
: "no") + "<br>");

if (Request.IsAuthenticated)
{
string[] roles = new string[] {"ChangeUser", "MoveUser"};

Thread.CurrentPrincipal = new GenericPrincipal(Context.User.Identity,
roles);
}
}

As I understand it, this should assign the "ChangeUser" and "MoveUser" roles
to the authenticated user, but it doesn't seem to work (or I am doing
something wrong). In my web form I have this:

private void Page_Load(object sender, System.EventArgs e)
{
if (Context.User.IsInRole("ChangeUser"))
{
Response.Write("<br>User is in role \"ChangeUser\"");
}
if (Context.User.IsInRole("MoveUser"))
{
Response.Write("<br>User is in role \"MoveUser\"");
}
}

This does not print out the "User is in role ..." as I would expect it to.
Any suggestions?
 
Reply With Quote
 
 
 
 
Hernan de Lahitte
Guest
Posts: n/a
 
      11-24-2004
Change this line:
Thread.CurrentPrincipal = new GenericPrincipal(Context.User.Identity,
roles);

To this:
Context.User = new GenericPrincipal(Context.User.Identity,
roles);

--
Hernan de Lahitte
http://weblogs.asp.net/hernandl


"Neils Christoffersen" <(E-Mail Removed)>
escribió en el mensaje
news:(E-Mail Removed)...
>I have a quick question about ASP.NET roles.
>
> I have the following in in Global.asax:
> protected void Application_AuthenticateRequest(Object sender, EventArgs e)
> {
> Response.Write("Request authenticated: " + (Request.IsAuthenticated ?
> "yes"
> : "no") + "<br>");
>
> if (Request.IsAuthenticated)
> {
> string[] roles = new string[] {"ChangeUser", "MoveUser"};
>
> Thread.CurrentPrincipal = new GenericPrincipal(Context.User.Identity,
> roles);
> }
> }
>
> As I understand it, this should assign the "ChangeUser" and "MoveUser"
> roles
> to the authenticated user, but it doesn't seem to work (or I am doing
> something wrong). In my web form I have this:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (Context.User.IsInRole("ChangeUser"))
> {
> Response.Write("<br>User is in role \"ChangeUser\"");
> }
> if (Context.User.IsInRole("MoveUser"))
> {
> Response.Write("<br>User is in role \"MoveUser\"");
> }
> }
>
> This does not print out the "User is in role ..." as I would expect it to.
> Any suggestions?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net 2.0 roles not working when deploying to web server Homer ASP .Net 5 07-20-2007 05:48 AM
Roles not working the way I expected.... any help appreciated. rob lynch ASP .Net Security 2 03-10-2006 05:44 PM
Custom RoleProvider + <allow roles> not working SJ ASP .Net Security 3 02-22-2006 09:30 PM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Application level roles + Item level roles... how to do it? Jéjé ASP .Net Security 0 09-26-2005 11:06 PM



Advertisments