加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 无法关闭asp.net 5 MVC 6站点中的requirehttps

发布时间:2020-12-16 07:25:30 所属栏目:asp.Net 来源:网络整理
导读:我有一个我正在研究的asp.net 5 MVC 6网站.我打开需要HTTPS,如下所示: services.AddMvc(options ={ options.Filters.Add(new RequireHttpsAttribute());}); 它工作得很好,我已经这样做了一段时间.今天我需要关闭它,所以我注释掉了选项过滤器,但它仍然需要HT
我有一个我正在研究的asp.net 5 MVC 6网站.我打开需要HTTPS,如下所示:

services.AddMvc(options =>
{
    options.Filters.Add(new RequireHttpsAttribute());
});

它工作得很好,我已经这样做了一段时间.今天我需要关闭它,所以我注释掉了选项过滤器,但它仍然需要HTTPS.

我没有在控制器或操作本身上使用[RequireHttps]属性.

我已进入属性并取消选中“启用SSL”并将“http URL”粘贴到“启动URL”框中.

我关闭了IIS Express并重新启动了该站点.它似乎并不重要,它继续尝试重定向到HTTPS.

IIS Express或Kestral是否可以缓存我需要删除的内容?
任何人都有任何建议,还有什么可能迫使它加入HTTPS?

解决方法

RequireHttpsAttribute实现将永久重定向响应(301)发送回浏览器:

// redirect to HTTPS version of page
filterContext.Result = new RedirectResult(newUrl,permanent: true);

这意味着当您最初启用了属性并请求了像http://localhost:62058/这样的URL时,服务器将响应:

301 (Moved permanently)
Location: https://localhost:62058/

如果您查看301响应代码的definition,您将看到默认情况下浏览器将缓存它:

The requested resource has been assigned a new permanent URI and any
future references to this resource SHOULD use one of the returned
URIs. Clients with link editing capabilities ought to automatically
re-link references to the Request-URI to one or more of the new
references returned by the server,where possible. This response is
cacheable unless indicated otherwise
.

The new permanent URI SHOULD be given by the Location field in the
response. Unless the request method was HEAD,the entity of the
response SHOULD contain a short hypertext note with a hyperlink to the
new URI(s).

删除RequireHttps过滤器后,浏览器仍将使用缓存的响应:

Getting cached redirect to https response

因此,在删除RequireHttps过滤器后,您需要做的就是重建并清除浏览器缓存!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读