【发布时间】:2017-01-09 00:01:04
【问题描述】:
我想在我编写的 LoginController 中对我的登录页面使用验证码
[HttpGet]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] // This is for output cache false
public FileResult GetCaptchaImage()
{
CaptchaRandomImage CI = new CaptchaRandomImage();
this.Session["CaptchaImageText"] = CI.GetRandomString(5); // here 5 means I want to get 5 char long captcha
//CI.GenerateImage(this.Session["CaptchaImageText"].ToString(), 300, 75);
// Or We can use another one for get custom color Captcha Image
CI.GenerateImage(this.Session["CaptchaImageText"].ToString(), 300, 75, Color.DarkGray, Color.White);
MemoryStream stream = new MemoryStream();
CI.Image.Save(stream, ImageFormat.Png);
stream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(stream, "image/png");
}
在我写的html部分
<span class="input-group-addon"style="width: 20%; background: transparent;border: none"><img src="@Url.Action("GetCaptchaImage","Login")" style="width:80px; height: 45px;margin-left: -12px" /></span>
问题是 Session 和 image 不相等,因为当登录页面加载时,首先验证码起作用然后页面起作用,所以会话总是存储以前的图像代码。我怎么解决这个问题? 谢谢
【问题讨论】:
标签: jquery html asp.net-mvc session captcha