![](/img/trans.png)
[英]Redirecting Response asynchronously in Custom HttpHandler ASP.Net MVC 5
[英]ASP.NET MVC Custom HttpHandler
我正在按照本教程在MVC應用程序中使用驗證碼: http : //coderjournal.com/2008/03/actionfilterattribute-aspnet-mvc-captcha/
我認為這是針對ASP.NET MVC的正式版本的,因為它確實對我有用。
問題是驗證碼映像永遠不會顯示,因為自定義處理程序(captcha.ashx)永遠不會收到請求。
在web.config中:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="GET" validate="false" path="captcha.ashx" type="SCE.Models.Helpers.Captcha.CaptchaHandler"/>
</httpHandlers>
處理程序:
namespace SCE.Models.Helpers.Captcha
{
public class CaptchaHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
string guid = context.Request.QueryString["guid"];
CaptchaImage ci = CaptchaImage.GetCachedCaptcha(guid);
if (String.IsNullOrEmpty(guid) || ci == null)
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not found";
context.ApplicationInstance.CompleteRequest();
return;
}
using (Bitmap b = ci.RenderImage())
{
b.Save(context.Response.OutputStream, ImageFormat.Gif);
}
context.Response.ContentType = "image/png";
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.ApplicationInstance.CompleteRequest();
}
}
}
似乎較新版本的MVC改變了他們路由處理程序的方式,但我不知道到底是什么...
有什么想法可以打電話給處理程序嗎?
更新:這是找到的解決方案Ive:在global.asax文件中:
routes.IgnoreRoute("{filename}.ashx/{*pathInfo}");
使用MVC 2和ReCaptcha,這是一個非常優雅的解決方案。 恕我直言
http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp-net-mvc.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.