Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.23/5 (3 votes)
See more:
wed config
XML
<location path="~/elmah.axd">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
</configuration>


and my appl_benRequest
C#
protected void Application_BeginRequest()
   {
       if (Request.Url.AbsolutePath.ToLowerInvariant().Contains("elmah.axd"))
       {
           // Check if user can see elmah and handle unauthorised users (return 401/redirect to login page/etc...)


       }
how to find login person roleid here plz help me out ...Thanks a lot in advance

   }
Posted

There are a number of methods that may be helpful to you.

Check out the System.Web.Security namespace

//find out if the current user is in the administrators role
User.IsInRole("Administrator")

//gives a list of all roles the current user is in
Roles.GetRolesForUser(User.Identity.Name)

//gives list of all users in administrators role
Roles.GetUsersInRole("Administrator")

If i needed to check if a user was in the Administrator role, i would do this
if (User.IsInRole("Administrator"))
{
//code
}
 
Share this answer
 
Comments
Member 10057465 23-May-13 5:43am    
Thanks a lot for response..
but problem is i am using application_BeginRequest method in Global.asax where above all methods
are getting NullReference exceptions...Plz Help me out
Sorry, i cannot figure out how to add code in a comment, so i am just submitting another answer.

XML
A couple of things I noticed.

You are doing this in your web.cofig:
<pre>
<location path="~/elmah.axd">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
</pre>
Now, if that is setup correctly, when someone not in the administrator group tries to view the elmah page, it will give them an access denied message.  There is no reason to check again in the global.asax.
Try changing:
<pre>
<location path="~/elmah.axd">
</pre>
To:
<pre>
<location path="elmah.axd">
</pre>

Even if you MUST check in the global.asax for some reason, the place would not be application_BeginRequest
Here is a link to an article that may help you find the right method to use in the Global.asax

http://stackoverflow.com/questions/3072768/net-application-beginrequest-how-to-get-user-reference
 
Share this answer
 
Comments
Member 10057465 31-May-13 10:36am    
thnxs for the response...it helped me thank u soo much..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900