CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Skip Navigation LinksHome » CodeDigest » Redirecting user to NotAuthorized page when tried accessing a restricted resource   You are not logged in.
Search
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Redirecting user to NotAuthorized page when tried accessing a restricted resource
Redirecting user to NotAuthorized page when tried accessing a restricted resource
Submitted By Satheesh Babu B
On 11/9/2008 5:00:12 AM
Tags: ASP.Net,CodeDigest  

Redirecting user to NotAuthorized page when tried accessing a restricted resource

 

When we use forms authentication with roles, the logged in user will be again forwarded to login page when he tries accessing a resource which his role is restricted.

 

This can be prevented and the user can be redirected to NotAuthorized page by adding the following code snippet in the Login Page_Load event.

 

 

protected void Page_Load(object sender, EventArgs e)

    {

if (User.Identity.IsAuthenticated && Request.QueryString["ReturnUrl"] != null)

        {

           

            Response.Redirect("NotAuthorized.aspx");

        }

    }

 

 

When the above included in the Login.aspx page load event, the user will be automatically redirected to Not Authorized Page when he tries accessing a restricted resource!

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..