asp.net-mvc – 在MVC3中的错误 – 请求永远不会超时 在同一项目中的aspx页面工作良好
|
我在我们的生产网站上看到这个,以及一个小的测试网站,我只是为了测试这个… 基本上,似乎由mvc处理的请求永远不会超时。我在我的web.config中设置了一个executionTimeout并关闭调试模式。然后我添加了一个无限循环的thread.sleeps到一个常规aspx页面和一个mvc页面(循环是在mvc页面的控制器)。 aspx页面可靠超时(HttpException(0x80004005):请求超时。),但是mvc页面只是旋转永远没有超时。 有没有单独的设置mvc(我看过,但没有找到它们)? Do mvc请求默认不超时? 任何帮助,这将不胜感激。我会很高兴地发电子邮件发送我的小测试网站,如果它会帮助任何人。 编辑:我使用MVC3。 我的web.config的内容: <?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application,please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
<system.web>
<httpRuntime maxRequestLength="16384" executionTimeout="30" />
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers,Version=1.0.0.0,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc,Version=3.0.0.0,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages,PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
解决方法我找到了这个的原因,methinks:此方法在WrappedAsyncResult类中,MvcHandler类通过BeginProcessRequest使用该类: public static IAsyncResult BeginSynchronous<TResult>(AsyncCallback callback,object state,Func<TResult> func,object tag)
{
BeginInvokeDelegate beginDelegate = delegate (AsyncCallback asyncCallback,object asyncState) {
SimpleAsyncResult result = new SimpleAsyncResult(asyncState);
result.MarkCompleted(true,asyncCallback);
return result;
};
EndInvokeDelegate<TResult> endDelegate = _ => func();
WrappedAsyncResult<TResult> result = new WrappedAsyncResult<TResult>(beginDelegate,endDelegate,tag);
result.Begin(callback,state,-1);
return result;
}
其中“Begin”是: public void Begin(AsyncCallback callback,int timeout)
{
bool completedSynchronously;
this._originalCallback = callback;
lock (this._beginDelegateLockObj)
{
this._innerAsyncResult = this._beginDelegate(new AsyncCallback(this.HandleAsynchronousCompletion),state);
completedSynchronously = this._innerAsyncResult.CompletedSynchronously;
if (!completedSynchronously && (timeout > -1))
{
this.CreateTimer(timeout);
}
}
if (completedSynchronously && (callback != null))
{
callback(this);
}
}
编辑:提出了一个ham-handed的方式强制MVC控制器的行动“超时”,虽然机制有点粗暴: public class TimeoutController : Controller
{
private bool _isExecuting = false;
private int _controllerTimeout = 5000;
private Thread _executingThread;
private readonly object _syncRoot = new object();
protected override void ExecuteCore()
{
_executingThread = Thread.CurrentThread;
ThreadPool.QueueUserWorkItem(o =>
{
Thread.Sleep(_controllerTimeout);
if (_isExecuting)
{
_executingThread.Abort();
}
});
base.ExecuteCore();
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
_isExecuting = true;
base.OnActionExecuting(filterContext);
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
_isExecuting = false;
base.OnActionExecuted(filterContext);
}
public int ControllerTimeout
{
get
{
int retVal;
lock(_syncRoot)
{
retVal = _controllerTimeout;
}
return retVal;
}
set
{
lock(_syncRoot)
{
_controllerTimeout = value;
}
}
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 模型需要注入依赖项时的模型(ViewModel)绑定
- asp.net-mvc – ASP.NET Azure 400错误请求不返回JSON数据
- asp.net-mvc – 自定义授权MVC 3和Ninject IoC
- 使用ASP.NET MVC3中的JavaScriptSerializer转义引号
- asp.net-mvc – ie9:调试时出现恼人的弹出:“错误:’__f
- asp.net-mvc – ASP.NET MVC:使用EditorFor()和枚举的默认
- asp.net-mvc – ASP MVC 5项目’New Scaffolded Item …’在
- asp.net – 用户控件的属性在回发后失去价值
- asp.net – 如何迭代DataTable中给定行中的所有项目
- asp.net-mvc – Url.Action with RouteValueDictionary wit
- 在.NET框架中强制使用英语异常
- asp.net – 任何方式构建Google文档,如PDF文件的
- asp.net-mvc – MVC不引人注目的范围验证动态值
- asp.net – 为什么不调用我的IHttpHandler?
- asp.net – 使用StartMode =“AlwaysRunning”在
- asp.net-mvc – 在asp.net mvc中选择列表用法
- asp.net-web-api – 在ASP.NET Web API控制器的n
- asp.net-mvc – 为什么要使用视图模型?
- asp.net-mvc – 为IIS托管的.SVC文件配置XML-RPC
- asp.net – 我应该继续研究MVC 1.0上的项目还是停
