Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery MVC验证码和会话是不同的_Jquery_Html_Asp.net Mvc_Session_Captcha - Fatal编程技术网

Jquery MVC验证码和会话是不同的

Jquery MVC验证码和会话是不同的,jquery,html,asp.net-mvc,session,captcha,Jquery,Html,Asp.net Mvc,Session,Captcha,我想在我写的LoginController中对我的登录页面使用验证码验证 [HttpGet] [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] // This is for output cache false public FileResult GetCaptchaImage() { CaptchaRandomImage CI = new C

我想在我写的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>

问题是会话和图像不相等,因为当登录页面加载时,首先验证码起作用,然后页面起作用,所以会话总是存储以前的图像代码。我怎样才能解决这个问题?
谢谢你

首先wiev启动,然后其他人启动,你的代码是正确的,但你应该在控制器中执行,而不是在视图中,你应该在你的post操作中添加一个参数authcode,然后在控制器中你可以检查和执行。

首先wiev启动,然后其他人启动,你的代码是正确的,但你应该在控制器中执行,而不是在视图中,您应该在post操作中再添加一个参数authcode,然后在控制器中进行检查和操作