protected void Page_Load(object sender, EventArgs e)
{
string checkCode = GetRandomCode(4);
HttpContext.Current.Session["CheckCodeKF"] = checkCode;
SetPageNoCache();
CreateImage(checkCode);
}
private void SetPageNoCache()
{
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.CacheControl = "no-cache";
HttpContext.Current.Response.AppendHeader("Pragma", "No-Cache");
}
private void CreateImage(string checkCode){这个是把获取到的写入到画板内然后返还给前台。}
//执行登陆事件
string yzm = Request.Form["checkword"];
if (Session["CheckCodeKF"] != null)
{
if (Session["CheckCodeKF"].ToString().ToLower() == yzm.ToLower())
{
//登陆代码
}
else
{
Response.Write("checkerror");
}
}
else
{
Response.Write("lost");
}
protected void Page_Load(object sender, EventArgs e)
{
string checkCode = GetRandomCode(4);
HttpContext.Current.Session["CheckCodeKF"] = checkCode;
HttpContext.Current.Session.Timeout = 5;
SetPageNoCache();
CreateImage(checkCode);
}
<system.web>
<sessionState mode="InProc" cookieless="false" timeout="5" />
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxQueryStringLength="2097151" executionTimeout="300"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<sessionState mode="InProc" cookieless="false" timeout="5" />也不管用、Session["CheckCodeKF"]这个获取的还是个null
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。