作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过在 Controller 操作上添加属性 [RequireSSL] 使我的登录页面启用了 Https,它工作正常。但是成功登录后它仍然在https环境中,但是该页面是非https页面。
谁能给我解决方法如何从 https 跳到 http 模式?
在这方面的任何帮助将不胜感激。
最佳答案
您基本上需要做相反的事情,即具有 [DoesNotRequireSSL] 属性,它实际上与 {RequireSSL] 属性相反,即重定向到 http 协议(protocol)
public class DoesNotRequireSSL: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
var response = filterContext.HttpContext.Response;
if (request.IsSecureConnection && !request.IsLocal)
{
string redirectUrl = request.Url.ToString().Replace("https:", "http:");
response.Redirect(redirectUrl);
}
base.OnActionExecuting(filterContext);
}
}
关于asp.net-mvc - 如何在 asp.net mvc 中从 https 模式跳到 http 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1566928/
我是一名优秀的程序员,十分优秀!