如何改变POST到SSL URL在MVC 4 [英] How to change POST to SSL URL in MVC 4
问题描述
我想知道是否有一个简单的方法,使用户的POST操作重定向到一个网站的HTTPS版本。因此,例如,一个用户进入 http://www.omegusprime.com/Request/ABC 并填表。我怎样才能使提交按钮后到 https://www.omegusprime.com/Request/ABC?
I wanted to know if there was an easy way to make the user' POST action redirect to the HTTPS version of a site. So for example a user goes to http://www.omegusprime.com/Request/ABC and fills out a form. How can I make the SUBMIT button post to https://www.omegusprime.com/Request/ABC?
我知道的RequireHttpsAttribute的,但是这并不影响Html.BeginForm()的行为。
I'm aware of the RequireHttpsAttribute, but that does not affect how the Html.BeginForm() behaves.
推荐答案
我同意保罗的回答。写普通的HTML标签,似乎这里是唯一的出路。
I agree with Paul's answer. Writing normal HTML Tag seems to be the only way here.
不过,我会建议使用HTML和MVC的URL助手的混合。它使肯定的是,网址是正确的,它使用了正确的域名。这是一个优势,当你有一个地方发展的版本(即 https://开头本地主机/申请/ ABC
)和生产版本( HTTPS:/ /www.omegusprime.com/Request/ABC
)。
But I would recommend using a mix of HTML and the URL Helper of MVC. It makes sure, the URL is right and it uses the correct domain name. This is an advantage when you have a local development version (i.e. https://localhost/Request/ABC
) and your production version (https://www.omegusprime.com/Request/ABC
).
VB例如:
VB example:
<form action="@Url.Action("ABC", "Request", Nothing, "https")" method="post">
...
</form>
应该是这样在C#中:
Should look like this in C#:
<form action="@Url.Action("ABC", "Request", null, "https")" method="post">
这篇关于如何改变POST到SSL URL在MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!