我已将IHttpHandlerFactory映射到“所有”http请求。
<httpHandlers>
<add verb="*" path="*.*" type="HomeController"/>
</httpHandlers>
从家庭控制器,我调用不同的HTTP控制器。
我的一些控制器必须将用户重定向到不同的.aspx文件。
问题:这会再次触发homecontroller(工厂),在无限循环中调用它。
工厂代码
public class HomeController : IHttpHandlerFactory
{
public HomeController()
{
}
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{ ....
return new HelloWorldHandler2();
....
}
public void ReleaseHandler(IHttpHandler handler)
{
if (this.handler.Equals(handler))
{
this.handler.busy = false;
}
//throw new NotImplementedException();
}
处理程序代码
public class HelloWorldHandler2 : IHttpHandler
{
public HelloWorldHandler2()
{
}
public bool busy = false;
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
// This handler is called whenever a file ending
// in .sample is requested. A file with that extension
// does not need to exist.
//Response.Write("<html>");
//Response.Write("<body>");
//Response.Write("<h1>backup handler</h1>" );
//Response.Write("</body>");
//Response.Write("</html>");
context.Handler = this;
Response.Redirect("About.aspx");
}
public bool IsReusable
{
// To enable pooling, return true here.
// This keeps the handler in memory.
get { return false; }
}
}
如您所见,工厂调用处理程序,处理程序重定向页面, 重定向再次调用工厂......