Role Based Forms Authentication in ASP.NET 2.0
page 11 of 16
by Satheesh Babu
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 65601/ 97

Redirecting user to NotAuthorized page

When a user who does not belong to admin role is already logged in and has tried accessing the admin section, unfortunately he will be again forwarded to the Login page. Refer to Figure 2.

Figure 2 – NotAuthorized Problem

Instead, if a "Not authorized" page is displayed, it will be more appropriate for this scenario.

We can achieve this by redirecting the user to NotAuthorized page by including the below code in Page_Load event of Login page.

Listing 12 - Not Authorized Page Redirection

if (User.Identity.IsAuthenticated && Request.QueryString["ReturnUrl"] != null)
{
  Response.Redirect("NotAuthorized.aspx");
}

The above code checks whether the user is authenticated and ReturnUrl is not null through which we can confirm that the user is trying to access a resource which he does not have access after authenticating.


View Entire Article

User Comments

Title: it works at once   
Name: snopbear
Date: 2008-08-26 9:32:07 AM
Comment:
When I log in with test1 or any of them, I get redirected to a HTTP Error 404 - Not Found page. Any ideas?
Title: Question   
Name: Jeff
Date: 2008-06-26 9:53:38 AM
Comment:
When you log into the site with a user, go to their homepage, then click logout, hit the BACK button enough, it will get you into the home page without credentials.

Once you hit refresh it kicks you out and you have to login again.

This happens in IE6. It seems to work in Firefox right.
Title: Something is wrong   
Name: Mike
Date: 2008-06-25 10:16:43 AM
Comment:
When I log in with test1 or any of them, I get redirected to a HTTP Error 404 - Not Found page. Any ideas?
Title: permissions and roles   
Name: tariq
Date: 2008-05-12 5:39:03 AM
Comment:
Hi,

I need to grant users with permissions depending on their roles. I have heard about Visual Guard .Net http://www.visual-guard.com/EN. before I start testing, do you have any feedback about this tool?

thank you
Title: Thnx   
Name: Dhaval Patel
Date: 2008-05-02 11:04:11 AM
Comment:
thanks buddy... it helped understanding it better.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-02 2:17:08 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search