Asp.net mvc httpRuntime属性没有';t在ASP.NET MVC中工作
我创建了新的asp.NETMVC3项目。然后我在Asp.net mvc httpRuntime属性没有';t在ASP.NET MVC中工作,asp.net-mvc,web-config,timeout,Asp.net Mvc,Web Config,Timeout,我创建了新的asp.NETMVC3项目。然后我在Web.config文件中添加了以下字符串: <compilation debug="false" targetFramework="4.5"/> <httpRuntime targetFramework="4.5" executionTimeout="1"/> 睡眠30秒后,我可以看到索引视图。为什么httpRuntime属性不起作用?我创建了一个新的测试项目,因为我无法在我的工作项目中实现按超时中断。我的工作项目在ii
Web.config
文件中添加了以下字符串:
<compilation debug="false" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" executionTimeout="1"/>
睡眠30秒后,我可以看到索引视图。为什么httpRuntime
属性不起作用?我创建了一个新的测试项目,因为我无法在我的工作项目中实现按超时中断。我的工作项目在iis上运行,测试项目在iis express上运行
我做错了什么
我尝试了这个答案中的所有内容,但没有成功该属性不适用于像ASP.NET MVC这样的异步框架。相反,应该使用像CancellationToken这样的协作取消机制。下面是一个例子:
[AsyncTimeout(30000 /* 30 seconds */)]
public ActionResult YourMethod(..., CancellationToken token) {
// perform some long-running work
while (StillNeedToPerformWork()) {
DoSomeWork();
token.ThrowIfCancellationRequested();
}
return ...;
}
我相信上面的例子需要MVC4或更高版本。MVC框架将自动读取[AsyncTimeout]属性,并提供适当的CancellationToken实例作为操作方法的参数
有关如何使用代码中的CancellationToken的更多信息,请参阅。另请参阅我的异步MVC文章,•使用取消令牌部分如果不提供取消令牌怎么办?我想在我的所有控制器上全局应用此功能。它是否具有全局默认设置?
[AsyncTimeout(30000 /* 30 seconds */)]
public ActionResult YourMethod(..., CancellationToken token) {
// perform some long-running work
while (StillNeedToPerformWork()) {
DoSomeWork();
token.ThrowIfCancellationRequested();
}
return ...;
}