views:

105

answers:

2

I have an ASP.NET site that uses a custom role provider to determine authorisation for different parts of the site. I have configured the authorised roles for different parts of the site in web.config.

If a user is not in a particular role, I'd like to be able to inform them which role they require to be able to access that part of the site, so that an accurate authorisation request can be generated and sent off for approval.

Is there a straightforward way of testing which roles can access a given page in the site?

A: 

you can put this in your web.config in custom error section

<error statusCode="403" redirect="~/AccessDenied.aspx"/>

When user is not authorized to view a specific page, it will be redirected to AccessDenied.aspx page.

Muhammad Akhtar
This wouldn't achieve role-specific feedback which I believe is what the question is asking for
MattH
Yeah I'm looking specifically for a way of saying to a user "you can access this page by requesting membership of role X".
Graham Watts
+1  A: 

Depending on your website set-up, it may practical to structure your websites into folders for each role. That way you can look at the URL to determine the role.

That being said I'm sure there's a way to programmatically find out what you set in the Location elements - but I don't know it sorry :)

MattH