473,791 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RoleManager & Session object

I am trying to build custom membership/role providers, inheriting from the
base membership/role providers because I have an existing database with user
authentication and roles. The membership part is fine but I'm not getting
something right on the roles. When the user logs in, I am getting a
delimited list of roles from the database and putting them into a Session
variable. I thought I could access that Session variable in the Role
provider class like this:

Public Overrides Function GetRolesForUser (ByVal userName As String) As
String()
Dim pipe As Char = Chr(124)
Dim roleList As String
If Not IsNothing(HttpC ontext.Current. Session("UserRo les")) Then
roleList =
Convert.ToStrin g(HttpContext.C urrent.Session( "UserRoles" ))
Else
'could also hit the database here if needed
roleList = "public"
End If
Return roleList.ToLowe r.Split(pipe)
End Function

When I run the application on a secured page, I always get a null reference
exception on the HttpContext.Cur rent.Session("U serRoles")). I can use
HttpContext.Cur rent in the code without a problem, but adding the Session
object will always produce an exception.

My two questions are:
1) Why can't the Role provider access the httpcontext.cur rent.Session object
(and is there a way to fix this)?
2) How can I attach the roles to the user at login time so that I don't have
to hit the database for role information on later page requests.

Joel Reinford
Data Management Solutions LLC
Jul 25 '06 #1
1 2365
My two questions are:
1) Why can't the Role provider access the httpcontext.cur rent.Session
object (and is there a way to fix this)?
This should answer your question: http://forums.asp.net/thread/1214615.aspx
2) How can I attach the roles to the user at login time so that I don't
have to hit the database for role information on later page requests.
The role provider can cache the roles in a cookie. This article should give
you all the info you need:
http://msdn2.microsoft.com/en-us/library/tksy7hd7.aspx.

HTH,

Bastiaan de Rijber
Jul 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1264
by: 1.1 SDK installed after the removal | last post by:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <authentication mode="Forms" /> <roleManager enabled="false" /> <!-- <roleManager enabled="true" /> --> <!-- BSam 06/06/2005 5:36PM --> <!-- Project http://localhost/MCSD70.315/chapter05/ADOTest/WebForm1.aspx reported error: -->
0
2114
by: SeanGallavan | last post by:
Our Environment: Two network load balanced (using Microsoft NLB software) webservers with session maintained in a SQL Server database. NLB is configured with no affinity settings and two network cards in each machine. Machine keys are identical on both webservers. There is no anti-virus software installed. SQL Server database is storing session information as specified by Microsoft guidelines.
10
12211
by: GreggTB | last post by:
I've got an page (LOGIN.ASPX) that receives the user's login information. During the page load, it checks the credentials against a database and, if validation is successful, creates an instance of an object that stores the user's basic profile data (username, user type, associated sales region, etc.). I've been taking this user info and placing it in the Session object like so... Session = user;
1
6429
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
2
2040
by: Dave | last post by:
I have an application running on a 3 server webfarm running Windows 2003 with SQLServer Session state. After running for several hours, I started getting the following error. When I access each app individually, only one of the servers seems to return this error when I step through a sequence. I was told that I'm trying to store an object not marked as Serializable but I've tested this on a dev machine storing session variables without...
0
2011
by: nicolasl | last post by:
Hello, I have built a custom roleManager Provider that I have turned into a dll so I can share it accross multiple applications. When I try to add it to a web.config file I get the following error: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Here is the web.config code:
7
2602
by: JP | last post by:
Hi folks I have the following settings for my Rolemanager roleManager enabled="true" cacheRolesInCookie="true" cookieTimeout="30" cookieSlidingExpiration="true" cookieName=".ASPXROLES" My Expectation was that any hit to the database after the initial load should be after 30 minutes for a session , however I have found that this is not the case and every time I do Roles.IsUserInRole in the UI, the database Stored Proc is being called.(...
0
7192
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
3
4031
by: at_the_gonq | last post by:
Hello, I am hoping to get some guidance on the following scenerio: I have a password protected site where users have various permissions. Are sessions the best way of storing the user's id? And if so, on load of a page should I be hitting the database for their permissions (based on the session stored user id), or should everything I need be stored in session variables to save the trip to the database? I have also wondered about...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.