我以前没有在 MVC 中使用过 httpHandlers。
但是我想在我的应用程序中停止会话超时。
我在这里找到了解决方案;http://www.dotnetcurry.com/ShowArticle.aspx?ID=453 http://www.dotnetcurry.com/ShowArticle.aspx?ID=453
但是,通过我的暗示,我收到了错误消息
找不到路径“/Shared/KeepSessionAlive.ashx”的控制器
或者没有实现 IController
所以 jquery;
$.post("/Shared/KeepSessionAlive.ashx", null, function () {
$("#result").append("<p>Session is alive and kicking!<p/>");
});
正在寻找控制器。如何停止此操作并执行处理程序代码?
我尝试将其放入我的 web.config 中;
<httpHandlers>
<add verb="*" path="KeepSessionAlive.ashx" type="XXXXXX.Views.Shared.KeepSessionAlive"/>
</httpHandlers>
尝试忽略路由中的 .ashx 文件,这样 MVC 就不会尝试将其路由到控制器操作:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("Shared/{resource}.ashx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
这将导致 MVC 路由忽略 /shared/ 中的 .ashx 文件;但是,它不适用于其他地方的 .ashx 文件。如果您希望它在所有子目录中工作,请尝试以下操作(归功于这个答案 https://stackoverflow.com/a/4856349/1043198对于这个技巧):
routes.IgnoreRoute("{*allashx}", new { allashx = @".*\.ashx(/.*)?" });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)