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: }