I am implementing a custom role provider. I am facing a problem which is exactly similar to http://forums.asp.net/t/967758.aspx/1. I am not able to access session or cookie inside my function
public override string[] GetRolesForUser(string username)
{
HttpCookie istCookie = HttpContext.Current.Request.Cookies["IST"];
if (istCookie != null)
{
string userRole = istCookie["Role"];
if (!string.IsNullOrEmpty(userRole))
{
return new string[] { userRole };
}
}
return new string[] { };
}
What ever the cookie that I am adding like below in my login page is not coming inside my GetRolesForUser() function
sajanemmanue...
Member
12 Points
21 Posts
sharing data between custom role provider implementation and aspx page
Feb 15, 2012 12:36 PM|LINK
Hello All,
I am implementing a custom role provider. I am facing a problem which is exactly similar to http://forums.asp.net/t/967758.aspx/1. I am not able to access session or cookie inside my function
public override string[] GetRolesForUser(string username) { HttpCookie istCookie = HttpContext.Current.Request.Cookies["IST"]; if (istCookie != null) { string userRole = istCookie["Role"]; if (!string.IsNullOrEmpty(userRole)) { return new string[] { userRole }; } } return new string[] { }; } What ever the cookie that I am adding like below in my login page is not coming inside my GetRolesForUser() functionprivate void CreateISTCookie(string istSessionID, string userRole) { HttpCookie istCookie = new HttpCookie("IST"); istCookie["SessionID"] = istSessionID; istCookie["Role"] = userRole; istCookie.Domain = ConfigurationManager.AppSettings["COOKIE_DOMAIN"]; Response.Cookies.Add(istCookie); }
Can any one suggest how to solve this or any better approach to share data between page and custom role provider class?
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: sharing data between custom role provider implementation and aspx page
Feb 17, 2012 11:38 AM|LINK
Hi,
1. Use HttpContext.Current.Request.Cookies["IST"].Values[0] to get SessionID
2. Use HttpContext.Current.Request.Cookies["IST"].Values[1] to get Role
Feedback to us
Develop and promote your apps in Windows Store