启用 SSL 时,IIS Express 默认使用 HTTPS 端口 44300
当您最初设置 IIS Express 以启用 SSL 时,它会将端口默认为 44300。不幸的是,当我尝试在 https://localhost/
上访问我的网站时,它无法工作,除非我使用端口号 44300 - https://localhost:44300/
。
这些链接是使用以下内容生成的:
<%= Html.ActionLink("Index", "Index", "Home", new { @action = "https://" + Request.Hostname + Url.Action("Index", "Home") }) %>
虽然是一个丑陋的解决方案,但 @action
关键字可以覆盖生成的路由,但这意味着应用程序似乎需要了解任何非标准端口(例如44300)。
问题是我要编写一些东西来解决仅在开发环境中出现的问题。
所以我的问题是... 如何将端口更改为 443 并拥有类似的 IIS Express?
我的网站配置如下:
<site name="MySite" id="2" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Inetpub\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:" />
<binding protocol="https" bindingInformation=":44300:" />
</bindings>
</site>
非常感谢。
更新:
此问题已由 Divya 回答 IIS 论坛。
When you initially set up IIS Express to enable SSL, it defaults the port to 44300. Unfortunately, when I try to access my site in on https://localhost/
it doesn't work unless I use the port number 44300 - https://localhost:44300/
.
The links are generated using the following:
<%= Html.ActionLink("Index", "Index", "Home", new { @action = "https://" + Request.Hostname + Url.Action("Index", "Home") }) %>
Although an ugly solution, the @action
keyword can override the generated route, but it means that the application would seemingly need to be aware of any non-standard ports (eg 44300).
The problem with that is that I'd be writing something to solve a problem that would only occur in a development environment.
So my question is... How do I change the port to 443 and have IIS Express like it?
Config for my site is below:
<site name="MySite" id="2" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Inetpub\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:" />
<binding protocol="https" bindingInformation=":44300:" />
</bindings>
</site>
Many thanks in advance.
Update:
This question has been answered by Divya over on the IIS forums.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
创建类
并在您的网络配置中添加类似的内容
然后您可以像这样使用它
Create class
And inside your web config add something like this
And then you use it like
Divya 在 IIS 论坛上回答了这个问题。
正如其他人所指出的,有几种获取 SSL 证书的好方法。
或(我的首选方法):
This question has been answered by Divya over on the IIS forums.
As noted by others, there are several nice ways of getting your SSL certs.
or (my preferred method):
由于我在这个主题上花了很多时间,我想分享我的发现。我正在重新发布我的另一篇文章中的片段,减去代码。一些背景和解释:
==============================================
经过研究后,我能够使用 IIS Express 和重写 Controller 类的 OnAuthorization 方法 (Ref#1) 解决此问题。我也选择了 Hanselman 推荐的路线(参考#2)。然而,由于两个原因,我对这两个解决方案并不完全满意:
OnAuthorization
仅适用于操作级别,不适用于控制器类级别因此,我想出了这个非常简单的解决方案,满足以下条件:
我希望能够在控制器类或操作级别使用
RequireHttps
属性我希望 MVC 在存在
RequireHttps
属性时使用 HTTPS,如果不存在则使用 HTTP我不想以管理员身份运行 Visual Studio
我希望能够使用 IIS Express 分配的任何 HTTP 和 HTTPS 端口
我可以重用 IIS Express 的自签名 SSL 证书,并且我不在乎是否看到无效的 SSL 提示
========================================== ===
你可以在这里找到我的解决方案/代码==> 仅在生产环境中使用 ASP.NET MVC RequireHttps
Since I have spent much time on this topic , I would like to share my finding. I am reposting segment from my other post minus the code. Some background and explanation:
==========================================
After researching aroud, I was able to solve this issue with IIS Express and an override of the Controller class's
OnAuthorization
method (Ref#1). I have also gone with the route recommended by Hanselman (Ref#2). However, I was not complete satisfied with these two solutions due to two reasons:OnAuthorization
only works at the action level, not at the controller class levelmakecert
),netsh
commands, and, in order to use port 80 and port 443, I need to launch VS2010 as administrator, which I frown upon.So, I came up with this solution that is quite simplistic with the following conditions:
I want to be able to use the
RequireHttps
attribute at Controller class or action levelI want MVC to use HTTPS when the
RequireHttps
attribute is present, and use HTTP if it is absentI do not want to have to run Visual Studio as administrator
I want to be able to use any HTTP and HTTPS ports that are assigned by IIS Express
I can reuse the self-signed SSL cert of IIS Express, and I do not care if I see the invalid SSL Prompt
=========================================
You can find my solution/code here ==> ASP.NET MVC RequireHttps in Production Only
端口 44300 是连续的:00 表示它是您配置为启用 SSL 的第一个应用程序; 01 将是第二个,依此类推。
由于我还通过添加
[RequireHttps]
全局属性要求我的网站只能在 HTTPS 下工作,因此我在调试时遇到了一些问题。启动时,它会自动重定向到https://localhost/
要解决此问题在调试网站时,我只需创建一个新的
RequireHttpsAttribute
> 指定端口仅在调试时使用此类。当部署到IIS7时,您应该使用Url重写来重定向到HTTPS。
The port 44300 is sequential: 00 mean that its the first application you have configured as SSL enabled; 01 will be the second one and so on.
Since I also require my website to only work in HTTPS by adding the
[RequireHttps]
global attribute, I had some trouble debugging. When launched, it was automatically redirecting tohttps://localhost/
To fix this problem when debugging a web site, I simply create a new
RequireHttpsAttribute
that specify the portUse this class when debugging only. When deployed to IIS7, you should use Url rewriting to redirect to HTTPS.
Dan 的答案是正确的,但如果您在配置 IIS Express 在标准端口上通过 http 和 https 为您的网站提供服务时仍然遇到问题,这里有一个很好的教程,可以逐步指导您:
http://www.lansweeper.com/kb/54/How-to-configure-SSL- in-IIS-Express.html
就我而言,我不小心删除了 IIS Express 证书。我认为它是您第一次在 Visual Studio 中使用 SSL 时生成的(在选定项目上按 F4 获取属性窗口并选中“SSS Enabled”复选框)。本教程指导我如何创建证书并修复它。
Dan answer is right but if you still have problems with configuring IIS Express to serve your website with http and https on standard ports here is nice tutorial that that guide you step by step:
http://www.lansweeper.com/kb/54/How-to-configure-SSL-in-IIS-Express.html
In my case I accidentally deleted IIS Express certificate. I think it is generated the first time you use SSL in Visual Studio (F4 on selected project to get properties window and checking 'SSS Enabled' checkbox). This tutorial guided me how to create certificate and fix it.