473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Role-Based Security with Forms Authentication

Hello,

I develop a web application with form authentication. When a user submit to
login my web application, my codes in Login.aspx.cs have save the member
info to Session["Member"]. But when I try to get the Session["Member"] in
Global.asax.cs, the browser occurs an error message
"System.NullReferenceException" at Line10. Can you tell me what's the
problem?

Thanks,
Simon

----------------------------------------------------------------------------
-------------
Login.aspx.cs
----------------------------------------------------------------------------
-------------
private void btnSubmit_Click(object sender, System.EventArgs e)
{
BLLMbr objBLLMbr = new BLLMbr();
MDLMbr objMDLMbr = objBLLMbr.Login(txtMbrId.Text, txtMbrPwd.Text);

if (objMDLMbr != null)
{
HttpContext.Current.Session["Member"] = objMDLMbr;

string url = FormsAuthentication.GetRedirectUrl(txtMbrId.Text,
false);
FormsAuthentication.SetAuthCookie(txtMbrId.Text, false);
HttpContext.Current.Response.Redirect(url);
}
}

----------------------------------------------------------------------------
-------------
Global.asax.cs
----------------------------------------------------------------------------
-------------
Line1: protected void Application_AuthenticateRequest(Object sender,
EventArgs e)
Line2: {
Line3: if (!(HttpContext.Current.User == null))
Line4: {
Line5: if (HttpContext.Current.User.Identity.AuthenticationT ype ==
"Forms" )
Line6: {
Line7: System.Web.Security.FormsIdentity id;
Line8: id =
(System.Web.Security.FormsIdentity)HttpContext.Cur rent.User.Identity;
Line9:
Line10: MDLMbr objMDLMbr =
(MDLMbr)HttpContext.Current.Session["Member"];
Line11: String[] myRoles = objMDLMbr.MbrRole;
Line12:
Line13: HttpContext.Current.User = new
System.Security.Principal.GenericPrincipal(id, myRoles);
Line14: }
Line15: }
Line16: }

Nov 22 '05 #1
0 660

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

Similar topics

1
by: tracy | last post by:
hi, just wonder, can we copy a role then add some new priviledges to the new role. hm.. i means, example; now i have a role named role_a. Then I copy role_a to create role_b. After I created...
2
by: Ted | last post by:
How do I grant all privileges for a schema that has a large number of existing tables, procedures, functions, etc to a newly created role, without having to issue a grant statement for each object...
1
by: Tom Dauria | last post by:
I have a SQL database with an Access front end. In the database I have a read only and a read write role. When a read only user opens the database I want all the fields on the form to be locked...
2
by: gudia | last post by:
How would I, using a sql script, copy permissions assigned to a user or a role in one or more databases to another user or a role in their respective databases? Help appreciated
8
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
0
by: ferherra | last post by:
Hi, Hope someone can help... I databind my gridview (asp.net 2.0) like this: GridView1.DataSource = Membership.GetAllUsers(); (MembershipUserCollection) GridView1.DataBind(); In the...
1
by: CK | last post by:
Does anyone have any experience with this? We have an exisitng sql database with user and role info. I need to write a custom role provider to use this data. Does anyone have any examples of this...
4
by: cybertoast | last post by:
i seem to have some misunderstanding about how roles work in sql server 2005. i see that i can add a role to a database (dbname->->properties->permissions->. THis allows me to add either users or...
3
by: Jo | last post by:
Hi, I know how to create membership user and to define role via "Administer website" in design mode of e.g. an ASP.NET login control. My questions are: 1) how to create a membership user...
2
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.