Posted: 9/12/2011
Hello Everyone,
I have created a Custom Role Provider . When the user log in, it accesses a webservice and access the roles granted to the particular user.
The roles are stored in a Session. i.e
Session("UserAccessRights") = accessRights
Now I want to access this session in GetRolesForUser in the Custom Role Provider. However I cannot seem to acess the Session object or cookies in the GetRolesForUser method of the Custom Role provider.
I researched online and read that Session object and Cookies do not work in the GetRolesForUser in the Custom Role Provider. What is the alternative option or way to access the Session("UserAccessRights") in GetRolesForUser
Please advice
Thanks
Kapil
Posted: 9/13/2011
The reason is that Session is not enabled during that method. IMO you can go for cookies for extra data for Role Provider.
More info at connect site http://connect.microsoft.com/VisualStudio/feedback/details/104452/session-is-null-in-call-to-getrolesforuser
I tried using cookies.
In my login.aspx I am using
Dim newCookie As HttpCookie = New HttpCookie("AccessRights") newCookie.Values.Add("AccessRights", accessRights)
Dim newCookie As HttpCookie = New HttpCookie("AccessRights")
newCookie.Expires = #12/31/2012# Response.Cookies.Add(newCookie)
newCookie.Expires = #12/31/2012#
Response.Cookies.Add(newCookie)
In GetRolesForUser, I am trying to retrive the information from the cookie
If Not Request.Cookies("accessRights") Is Nothing Then
Dim foo as String = (Request.Cookies("accessRights").Value
End if
But it does not like the syntax. Get " Reference to a non-shared member requires an object reference error.
Please advice
Kapil
The error is different, you can't use the class name itself to qualify a non shared member. You need create an instance first and then reference the method by the instance.
Im GetRolesuser, I tried getting the cookie value as
Dim newCookie As HttpCookie = New HttpCookie("AccessRights") Dim foo As String = newCookie("AccessRights") But the value of the cookie was Nothing Please advice Kapil
Dim foo As String = newCookie("AccessRights")
But the value of the cookie was Nothing