TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
dhaval patel
NA
186
28.9k
How to Access page to multiple roles in asp.net
Sep 1 2018 2:53 AM
I have a one application in Asp.net with Linq and i already done with single role but i want to make multiple roles to single page.
Please review my code and please help me how to do it.
In Login Page i pass the roles to login user please see below code
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, txtname.Text.Trim(), DateTime.Now, DateTime.Now.AddMinutes(2880), true, data[0].RoleName, FormsAuthentication.FormsCookiePath);
Next i Write Code in Global.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
}
}
}
}
And Now in Page coding page load event i write below code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
Response.Redirect("~/Logintest.aspx");
}
if (!this.Page.User.IsInRole("Administrator"))
{
Response.Redirect("~/Logintest.aspx");
}
}
}
Now I Want USe Multiple Roles To Access Particular Page in This section.
if (!this.Page.User.IsInRole("Administrator"))
{
Response.Redirect("~/Logintest.aspx");
}
Its for Asp.net not MVC.
Please help me how to do it.
Reply
Answers (
5
)
How to add Dynamic Columns to my UI in asp.netmvc
How to get the buttn1 event value into another buttn2 event