Redirect unauthorized users to a custom page error
<p>I'm trying to redirect unauthorized users to a custom page when they are accessing administrator pages but I'm getting errors..</p>

<p>Web.Config For Administrator Folder</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;authorization&gt;
      &lt;allow roles="Administrators" /&gt;
      &lt;deny users="*"/&gt;
    &lt;/authorization&gt;
  &lt;/system.web&gt;
&lt;/configuration&gt;
</code></pre>

<p>Login page code:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.IsAuthenticated &amp;&amp; !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                    Response.Redirect("~/ErrorUNTH.aspx");
            }
}
</code></pre>

<p>ERRORS After loggin as NORMAL USER and accessing Administrator page:</p>

<pre><code>Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a "web.config" configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its "mode" attribute set to "Off".


&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode="Off"/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's &lt;customErrors&gt; configuration tag to point to a custom error page URL.


&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;
</code></pre>
