Asp.net MVC 5:表单处理完毕后,重定向不起作用 [英] Asp.net MVC 5: after form has been processed, redirect does not work

查看:123
本文介绍了Asp.net MVC 5:表单处理完毕后,重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个用ASP.NET 5编写的现有项目。在这里有一个表单,上面是一个按钮。此按钮被按下多次(约3小时内最多400次)。今天我进行了6小时的自动化测试,按下按钮大约1000次。突然间,放置按钮的表单的post方法不再可用。我正在使用带有IIS 8的Windows Server 2012.我的表单如下所示:



Hi, i'm currently working on an already existing project which is written in ASP.NET 5. In this there is a form on which is a button. This button gets pressed many times (up to 400 times within 3 hours approx). Today i made an automated test run for 6 hours in which the button was pressed roughly 1000 times. Suddenly the post method for the form in which the button is placed was not reachable anymore. I'm using Windows Server 2012 with IIS 8. My form looks like this:

@using (Html.BeginForm("PerformanceControl", "Performance"))
{
      //some stuff left out
      <div class="col-md-12 col-sm-12">
             <button name="button" src value="forwardRecord" class="btn btn-primary">
                                  Next Chunk  
             </button>
       </div>
}





接收邮寄方式如下:





The receiving post method looks like this:

[HttpPost]
public IActionResult PerformanceControl(int id, string button, ShowPerformanceControlViewModel viewModel)
{//id is projectID
	//Do some stuff
             return RedirectToAction("PerformanceControl");
}





我遗漏了逻辑代码,因为这是一个非常大的方法。

使用相同的URL模式调用性能控件的POST和GET方法:/ Performance / PerformanceControl / 11(十一只是一个示例ID)。

调用的GET版本发生错误时仍然有效。我是ASP.NET的新手,所以我真的不知道这种奇怪行为的原因,特别是当它在同一个会话中工作了1000次并且会话数据没有丢失时。端点只能再到达了吗?



更新:



我现在已经设法重新创建问题,起初我认为这是POST请求,但事实证明,处理表单数据后的GET请求失败,但是当我点击重新加载时,网站正常工作。 ASP.NET中的重定向是否存在常见问题?



PS:对不起,我的母语是德语。



我尝试了什么:



我查看了服务器的所有日志我唯一的事情可以找到的是,在14:20(20.06.2018)之后,每个帖子请求发布表格的方法都不再有效。我网站上的其他表单,例如登录和注册表单仍然没有问题。我还查看了窗口事件查看器,但我找不到任何可疑条目。只有重启asp.net网站才能恢复生命。我还检查了是否存在数据库错误,但是没有。



I have left out the logic code because it's a very big method.
The POST and GET method of the performance control are getting called with the same URL pattern: "/Performance/PerformanceControl/11" (the eleven is just an example ID).
The GET version of the call still works when the error occurs. I'm new to ASP.NET so i don't really what could be the reason for this strange behaviour especially when it worked 1000 times in the same session and the session data was not lost. The endpoint was only not reachable anymore?

Update:

I have now managed to recreate the problem and at first i thought it was the POST request but it turns out that the GET request after processing the form data fails, but when i hit reload the site works. Is there a common problem with redirect in ASP.NET?

P.S.: Sorry for my bad englisch, my native language is german.

What I have tried:

I have looked through all the logs of the server the only thing i could find was that after 14:20 (20.06.2018) every post request to post Method of the form didn't work anymore. Every other form on my website e.g. Login and Registration form did still work without a problem. I have also looked through the window event viewer but i could not find any suspicious entries. Only a restart of the asp.net site brought the form back to life. I also checked if there are database errors but there arent.

推荐答案

您已经发现重定向无效的原因:表单方法是GET所以POST操作将永远不会发生。



非常简单的修复,将表格上的方法更改为POST

You have already discovered why the redirect is not working: the form method is GET so the POST action will never occur.

Very easy fix, change the method on the form to POST
@using (Html.BeginForm("PerformanceControl", "Performance", FormMethod.Post))


这篇关于Asp.net MVC 5:表单处理完毕后,重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆