【发布时间】:2015-06-16 02:41:03
【问题描述】:
//************ Try Block ************************************//
sqlStr = "select LoginId from users where LoginID like '" + sUserName.Trim() + "' and CurrentPassword like '" + objFun.EncryptData(sPassword.Trim()) + "'";
string sDbUserName = objFun.RunSelectQueryAndReturnString(sqlStr);
if (sUserName.ToUpper().Trim() == sDbUserName.ToUpper().Trim())
{
sqlStr = "select CurrentStatus from users where LoginID like '" + sUserName.Trim() + "' and CurrentPassword like '" + objFun.EncryptData(sPassword.Trim()) + "'";
int iStatus = Convert.ToInt32(objFun.RunSelectQueryReturnFirstFieldOfFirstRecord(sqlStr));
if (iStatus != 1)
{
Response.Cookies.Add(new HttpCookie("UserName", sUserName));
Session["LoginID"] = sUserName; // From this line my Code goes to Catch Block
Session["LoginTime"] = DateTime.Now;
sqlStr = "";
sqlStr = "Update Users set CurrentStatus=1 where LoginID like '" + sUserName + "'";
objFun.RunSelectQuery(sqlStr);
if (Login1.RememberMeSet == true)
{
Response.Cookies.Add(new HttpCookie("UserNameHistory", Login1.UserName));
}
sqlStr = "";
objFun.GenerateLog("USERLOGIN", "Logged in into Website", sUserName, 2, 0);
Response.Redirect("Home.aspx");// ,true );
//throw new Exception("Unable to redirect");
}
else
{
throw new Exception("User is already logged in");
}
///****************************Catch Block********************************/
catch (Exception ex)
{
Login1.FailureText = ex.Message;
}
Exception I got at RUNTIME:
{System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.
at System.Web.UI.Page.get_Session()
at Login.Login1_Authenticate(Object sender, AuthenticateEventArgs e)
【问题讨论】:
-
您是否启用了错误跟踪中指出的会话状态?到目前为止,您还尝试过其他任何事情吗?
-
是的,我启用了以下方式:在 Login.aspx 页面中
-
您是否启用了 SessionStateModule 或在 web.config 中提供了自定义?
-
发布您的网络配置,@David W 是正确的
-
无法在此评论框中发布 Web.Config 但我的 web.Config 文件中没有任何 EssionStateModule