我知道有很多帖子,如果我调用的操作方法只是一个 get 方法,它工作正常,但如果操作方法有一个 'Post' 属性,它会失败,因为在代码中我们重定向到网址而不是帖子
我正在使用下面的代码...
using System;
using System.Web;
using System.Web.Mvc;
namespace Helpers
{
public class RequiresSSL : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestBase req = filterContext.HttpContext.Request;
HttpResponseBase res = filterContext.HttpContext.Response;
//Check if we're secure or not and if we're on the local box
if (!req.IsSecureConnection && !req.IsLocal)
{
var builder = new UriBuilder(req.Url)
{
Scheme = Uri.UriSchemeHttps,
Port = 443
};
res.Redirect(builder.Uri.ToString());
}
base.OnActionExecuting(filterContext);
}
}
}
最佳答案
如果您还没有弄清楚这一点,[RequireHttps]
已集成到框架中。将该属性放在您打算确保安全的方法上。
关于asp.net-mvc - 将 ssl 与 aspnet mvc 一起使用会在将数据发布到安全页面时产生问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2364010/