Bypass Forms Authentication Or Skip Authorization for selected pages in asp.net
In my previous articles i explained how to use forms authentication in asp.net
1. C# Forms Authentication using ticket and managing user roles in asp.net
2. ASP.NET 2.0 - Forms Authentication with C# and managing folder lavel access with multiple web.config files
And i also explained about how to validate use across pages using session and redirect to login page if user is not logged in
User validation across pages using session after login in ASP.NET using C sharp
Some readers ask me how to skip or bypass forms authentication or Authorization for selected pages in asp.net or a scenario where only few pages on site needs user to log in rest can be accessed without login.
For this we need to set HttpContext.Current.SkipAuthorization property to true in global application class called Global.asax
You can write code like this
string Url = Request.RawUrl;
int count = Url.Length - 10 ;
string TestUrl = Url.Substring(count);
string SessionData = Session["Authenticate"].ToString();
if (TestUrl != "Admin.aspx")
{
HttpContext.Current.SkipAuthorization = true;
}
Here i'm checking if the page url is not Admin.aspx than skip the authentication check
You can use multiple && (and) or || (or) conditions with this
Download the sample code attached
Related posts:
ASP.NET Submit form on Enter Key Default submit Button
Register custom controls dlls and user controls ascx in ASP.NET
Search records in GridView with searchbox in footer and highlight results using AJAX
User validation across pages using session after login in ASP.NET
Creating OpenFileDialog in winforms to open or browse for the file in .NET windows application using C#
Bypass Forms Authentication Or Skip Authorization Asp.Net
Posted by
Unknown
If you like this post than join us or share
Labels: ASP.NET, Authentication, Forms Authentication, Session
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment