有没有办法确保 ASP.NET 应用程序(仅)在 HTTPS 协议上运行?
我想知道是否有一种方法可以确保 ASP.NET 应用程序只能使用 HTTPS 协议运行
我对任何可以做到这一点的代码(也许是防御性编程措施?)都很好,或者可能是一些 IIS/可以完成工作的 Web 服务器设置。
I'm wondering if there is a way to ensure that an ASP.NET application can only be run using the HTTPS protocol
I'm fine with any code (defensive programming measure perhaps?) that can do the trick, or possibly some IIS/web server setting that can get the job done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IIS 肯定会允许您需要 HTTPS。 说明位于此处。
编辑:我必须去挖掘它,但还有Request.IsSecureConnection 用于防御性编程。
IIS will definitely allow you to require HTTPS. The instructions are here.
Edit: I had to go dig for it, but there's also Request.IsSecureConnection for defensive programming.
在 IIS 级别强制实施 SSL 的唯一问题是用户会收到难看的 403.4 页面错误
为了实现无缝转换,如果用户不通过 SSL 生成请求,您可以使用
Request.IsSecureConnection
将用户重定向到安全站点。The only problem with enforcing the SSL on the IIS level is that the user receives an ugly 403.4 page error
To make the transition seamless, you could redirect the user to the secure site using the
Request.IsSecureConnection
if they do not generate the request over SSL.有一篇不错的文章,其中包含有关此主题的一些有用信息和帮助实用程序类,网址为leastprivilege.com
There is a nice article that has some good information and a helper utility class on this subject over at leastprivilege.com