Roles not working

  • Thread starter Neils Christoffersen
  • Start date
N

Neils Christoffersen

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?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top