dev*_*ric 31 timeout asp.net-core-mvc asp.net-core
我在我的ASP.NET Core MVC
视图页面中使用了ajax调用
MyView.cshtml
$.ajax({
processData: false,
contentType: false,
data: new FormData(this),
type: $(this).attr('method'),
url: $(this).attr('action'),
cache: false,
success: function (data) {
$('#mydiv).html(data);
$('#bootstrapModal).modal('show');
Run Code Online (Sandbox Code Playgroud)
控制器发布方法"
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> MyLongRunningMethod(MyViewModel viewModel)
{
await MyProcess.Longprocess1();
await MyProcess.Longprocess2();
await MyProcess.Longprocess3();
await MyProcess.Longprocess4();
return PartialView("_MyPartialPage");
}
Run Code Online (Sandbox Code Playgroud)
这有效,但只对长时间运行的过程有问题.在调试模式下,当进程花费的时间超过大约2分钟时,我收到以下错误
我理解这与过期超时有关
在以前版本的ASP.NET MVC中,您显然可以增加asp.net控制器操作的超时.
HttpContext.Current.Server.ScriptTimeout = 90000;
Run Code Online (Sandbox Code Playgroud)
然而,这不存在于 ASP.NET Core
我想增加特定asp.net控制器的调试和部署超时.
对于生产,我可以web.config
通过将requestTimeout添加到现有的httpPlatform标记来全局设置它.例如10分钟
<httpPlatform requestTimeout="00:10:00" ....
Run Code Online (Sandbox Code Playgroud)
一个类似的问题被问到,但答案给出了使用CancellationToken
但阅读它,它似乎不能帮助我超时.
ASP.NET 4
?dev*_*ric 47
设置RequestTimeout="00:20:00"
在aspNetCore
标签和部署该网站将导致其不会超时.
现在只在从Visual Studio调试模式运行但不在发布模式下运行时才会出现问题.
请注意:在ASP.NET RTM中,httpPlatform
标记已替换 aspNetCore
为web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore requestTimeout="00:20:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
Ива*_*рий 28
但在2.0 web.config
中,项目中没有文件.它是自动生成的.
我通过添加.UseKestrel(...)
到文件中的BuildWebHost
函数解决了这个问题,Program.cs
如下所示:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(o => { o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); })
.Build();
}
Run Code Online (Sandbox Code Playgroud)
gez*_*ead 17
在我的情况下,即使更新requestTimeout
参数后,我们仍然在2分钟时出现502超时错误.事实证明,红隼有一个2分钟的保持活动超时需要被覆盖:
var host = new WebHostBuilder()
.UseKestrel(o =>
{
o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
}
)
Run Code Online (Sandbox Code Playgroud)
自 .Net Core 3.1 以来,已接受的答案已更改。在 NET Core 3.1 中,使用以下实现来增加 KeepAliveTimeout:
程序.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel(options =>
{
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(15);
});
});
Run Code Online (Sandbox Code Playgroud)
Web.Config(如果不存在,您需要将配置文件添加到您的项目中。)
根据需要在 web.config 上增加 requestTimeout:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified"/>
</handlers>
<aspNetCore requestTimeout="00:15:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
小智 6
对我来说这有效:
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureKestrel(o => { o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
35843 次 |
最近记录: |