本文介绍了ASP.NET MVC - HTML.BeginForm和SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到什么应该在ASP.NET MVC一个简单的登录表单的问题2.从本质上我的形式看起来有点像这样:

I am encountering an issue with what should be a simple logon form in ASP.NET MVC 2. Essentially my form looks a little something like this:

using (Html.BeginForm("LogOn", "Account", new { area = "Buyers" }, FormMethod.Post, new { ID = "buyersLogOnForm" }))

我对登录操作方法RequiresHTTPS过滤器,但在执行时我收到以下消息

I have a RequiresHTTPS filter on the LogOn Action method but when it executes I receive the following message

所请求的资源只能是
  通过SSL访问

在这一点上只有工作的解决方案是一个额外的行动htmlattribute通过如下:

At this point the only solution that worked was to pass in an extra action htmlattribute as follows:

 var actionURL = "https://"  + Request.Url.Host + Request.Url.PathAndQuery;
 using (Html.BeginForm("LogOn", "Account", new { area = "Buyers" }, FormMethod.Post, new { ID = "buyersLogOnForm", @action = actionURL }))

虽然这工作我不知道一)为什么我看到摆在首位这个问题和b)如果从HTTP页面发布到https的一个更简单的方法?

While this works I wonder a) why i am seeing this issue in the first place and b) if there is a more straightforward way of posting to https from a http page?

我应该指出,在登录下拉列表将可在许多公共网页。我不希望我的所有网页的是HTTPS。举例来说,我希望网页 - 任何人都可以看到的 - 不应该基于HTTPS的。基本上我需要在我的形式指定协议,但不知道该怎么做,或者如果它是可能的。

I should have stated that the logon dropdown will be available on many public pages. I do not want all of my pages to be HTTPS. For instance, my hope page - which ANYONE can see - should not be HTTPS based. Essentially I need to specify the protocol in my form but have no idea how to do that, or if it is possible.

我想AP preciate任何意见/建议。
在此先感谢

I would appreciate any advice/suggestions.Thanks in advance

JP

推荐答案

您可以使用

<form action =" <%= Url.Action(
"action",
"controller",
ViewContext.RouteData.Values,
"https"
) %>" method="post" >

这篇关于ASP.NET MVC - HTML.BeginForm和SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:05