Loading ...

Using Sessions and Cookies in Custom Role Provider in ASP.NET 2.0

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  security   » Using Sessions and Cookies in Custom Role Provider in ASP.NET 2.0

Using Sessions and Cookies in Custom Role Provider in ASP.NET 2.0

Posts under the topic: Using Sessions and Cookies in Custom Role Provider in ASP.NET 2.0

Posted: 9/12/2011

Lurker 15  points  Lurker
  • Joined on: 9/12/2011
  • Posts: 3

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

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

The reason is that Session is not enabled during that method. IMO you can go for cookies for extra data for Role Provider.


Posted: 9/13/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Posted: 9/13/2011

Lurker 15  points  Lurker
  • Joined on: 9/12/2011
  • Posts: 3

I tried using cookies.

In my login.aspx I am using

 Dim newCookie As HttpCookie = New HttpCookie("AccessRights")

 

newCookie.Values.Add("AccessRights", accessRights)

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


Posted: 9/13/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

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.


Posted: 9/13/2011

Lurker 15  points  Lurker
  • Joined on: 9/12/2011
  • Posts: 3

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


Page 1 of 1 (6 items)