bzarah
bzarah

Reputation: 358

ASP.Net - How to determine if web request is to a resource that allows anonymous users or not

I have denied anonymous access to the entire application using the following Web.Config setting:

<authorization>
   <deny users="?" />
</authorization>

Then, for various paths, I have allowed anonymous access using Web.Config settings such as this:

<location path="Home/ShowLogin">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

I'd like to be able to determine during the processing of a given request whether the requested URL is to path that allows anonymous users or whether the request is to a path that denies anonymous users.

What is the most elegant way of determining this?

Upvotes: 0

Views: 219

Answers (1)

Daniel
Daniel

Reputation: 1793

You can use the following code to get the collection of location elements:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
foreach (ConfigurationLocation location in config.Locations)
{
  // work with location object
}

Upvotes: 1

Related Questions