简体   繁体   English

在IIS / IIS Express中发现已配置的HTTPS端口?

[英]Discover configured HTTPS port in IIS / IIS Express?

Using the [RequireHttps] port in an ASP.NET MVC application causes a redirect to HTTPS on port 443 if the user attempts to access the application over HTTP. 如果用户尝试通过HTTP访问应用程序,则在ASP.NET MVC应用程序中使用[RequireHttps]端口会导致在端口443上重定向到HTTPS。

However, in IIS Express, the application will probably not running on port 443. It will, instead, be running on something like port 44301. 但是,在IIS Express中,应用程序可能无法在端口443上运行。相反,它将在端口44301上运行。

I've found various tips for replacing RequireHttpsAttribute with an implementation that takes the alternative port number as a parameter, or reads it from Web.config . 我找到了用一个实现来替换RequireHttpsAttribute各种技巧,该实现将备用端口号作为参数,或者从Web.config读取它。

This is clunky, because it requires configuration in more than one place. 这很笨重,因为它需要在多个地方进行配置。

Is there any way to do this -- programmatically -- in a generic fashion? 有没有办法以通用方式以编程方式执行此操作?

Without trying to pre-empt the answers, some options occur to me: 在没有试图抢先回答的情况下,我想到了一些选择:

  1. Is there any way to discover the bindings being used by the instance of IIS or IIS Express that's hosting my app? 有没有办法发现托管我的应用程序的IIS或IIS Express实例使用的绑定?
  2. Is there any way to read applicationHost.config for the current IIS / IIS Express host? 有没有办法读取当前IIS / IIS Express主机的applicationHost.config

You can check currently used bindings (of IIS/IIS Express) by running following command 您可以通过运行以下命令来检查当前使用的绑定(IIS / IIS Express)

"netsh http show servicestate view=requestq" “netsh http show servicestate view = requestq”

You can find applicationhost.config file of IIS Express in %userprofile%\\documents\\iisexpress\\config folder. 您可以在%userprofile%\\ documents \\ iisexpress \\ config文件夹中找到IIS Express的applicationhost.config文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM