Nic*_*rdi 296 iis iis-7 iis-express
传统上我使用我的localhost开发服务器的自定义域.有点像:
dev.example.com
dev.api.example.com
Run Code Online (Sandbox Code Playgroud)
在使用Facebook等外部API时,这为我提供了很大的灵活性.这在过去使用内置的Visual Studio开发服务器时效果很好,因为我需要做的就是为那些指向的DNS记录添加一个CNAME 127.0.0.1.
但是我无法使用IIS Express.我尝试的一切似乎都失败了.我甚至已经applicationHost.config为IIS Express 的文件添加了正确的XML配置,但它似乎没有认识到这些条目与IIS的真正安装一样有效.
<binding protocol="http" bindingInformation="*:1288:dev.example.com" />
Run Code Online (Sandbox Code Playgroud)
每当我输入此行并尝试请求时,http://dev.example.com:1288我会收到以下消息:
错误请求 - 无效的主机名
有人知道我是否遗漏了一些明显的东西吗?或者,IIS Express团队是否真的缺乏远见才能看到这种用途?
Dav*_*och 358
这对我有用(更新了VS 2013,请参阅2010年的修订历史,对于VS 2015,请参阅:https://stackoverflow.com/a/32744234/218971):
Properties▶▶ Web,然后Servers按如下所示配置该部分:
http://localhosthttp://dev.example.comDefault Site为除端口之外的任何内容:80,确保Skype未使用端口80等)Start URL为http://dev.example.com打开%USERPROFILE%\My Documents\IISExpress\config\applicationhost.config(Windows XP,Vista和7)并在<sites>配置块中编辑站点定义,使其符合以下几行:
<site name="DevExample" id="997005936">
<application path="/" applicationPool="Clr2IntegratedAppPool">
<virtualDirectory
path="/"
physicalPath="C:\path\to\application\root" />
</application>
<bindings>
<binding
protocol="http"
bindingInformation=":80:dev.example.com" />
</bindings>
<applicationDefaults applicationPool="Clr2IntegratedAppPool" />
</site>
Run Code Online (Sandbox Code Playgroud)如果运行MVC:确保将applicationPool其设置为"Integrated"选项之一(如"Clr2IntegratedAppPool").
hosts文件并添加该行127.0.0.1 dev.example.com.评论提出了一些很好的建议:
- 您可能需要以管理员身份运行Visual Studio.
- 如果你想让其他开发者看到你的IIS运行
netsh http add urlacl url=http://dev.example.com:80/ user=everyone- 如果您希望站点解析所有主机集
bindingInformation="*:80:".使用你想要的任何端口,80只是方便.
njf*_*ife 146
对于Visual Studio 2015,上述答案中的步骤适用,但applicationhost.config文件位于新位置.在您的"解决方案"文件夹中按照路径进行操作,如果您升级并且applicationhost.config在您的计算机上有两个版本,这会让您感到困惑.
\.vs\config
Run Code Online (Sandbox Code Playgroud)
在该文件夹中,您将看到applicationhost.config文件
或者,您可以在解决方案文件夹中搜索.config文件并找到它.
我个人使用以下配置:
在我的hosts文件中有以下内容:
127.0.0.1 jam.net
127.0.0.1 www.jam.net
Run Code Online (Sandbox Code Playgroud)
以及我的applicationhost.config文件中的以下内容:
<site name="JBN.Site" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Dev\Jam\shoppingcart\src\Web\JBN.Site" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:49707:" />
<binding protocol="http" bindingInformation="*:49707:localhost" />
</bindings>
</site>
Run Code Online (Sandbox Code Playgroud)
请记住以管理员身份运行visual studio 2015的实例!如果您不希望每次我推荐这样做:
我希望这对某人有所帮助,我在尝试升级到Visual Studio 2015时遇到了问题,并意识到我的配置都没有被转移.
dma*_*son 44
将Visual Studio 2012与IIS Express一起使用时,更改现有绑定不会永久有效.(它可能会工作,直到你关闭VS,但在那之后,事情变得非常混乱.)
关键是保持现有的localhost绑定并在其后添加新绑定.
除非您以管理员身份运行,否则您还需要运行netsh add urlacl(以授予您自己作为标准用户运行非本地主机站点的权限).
如果要允许任何主机名,则完整过程如下:
从管理员提示符处,运行以下命令(将portnumber替换为您在#1中计算出的端口号):
netsh http add urlacl url="http://*:portnumber/" user=everyone
netsh http add urlacl url="http://localhost:portnumber/" user=everyone
Run Code Online (Sandbox Code Playgroud)您还可以使用您的用户名(DOMAIN\USER)代替所有人,以提高安全性.
使用所需的主机名添加一个绑定(在本例中为*).例如:
<site name="MvcApplication1" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\sites\MvcApplication1" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:12853:localhost" />
<binding protocol="http" bindingInformation="*:12853:*" />
</bindings>
</site>
Run Code Online (Sandbox Code Playgroud)请注意,如果要打开所有主机名(*),则需要两个netsh命令(一个用于*,一个用于localhost).如果您只想打开特定的主机名,则不需要第二个netsh命令(localhost); 只有具有您特定主机名的那个就足够了.
Jar*_*sky 24
无效的主机名表示您在IIS Express配置文件中配置的实际站点(很可能)未运行.IIS Express没有像IIS那样的进程模型.
要使您的站点运行,需要显式启动(通过打开和访问webmatrix,或从命令行调用iisexpress.exe(来自它的安装目录)和/ site参数.
通常,允许使用完全限定的DNS名称进行本地访问的步骤是让我们使用您的DNS名称示例dev.example.com
为您的站点配置IIS Express绑定(例如:Site1)以包含dev.example.com.使用绑定需要管理权限.或者,可以使用http.sys进行一次性URL保留
netsh http add urlacl url=http://dev.example.com:<port>/ user=<user_name>
iisexpress /site:Site1在WebMatrix中启动或打开Site1
rym*_*ymo 19
在我的WebMatrix IIS快速安装更改"*:80:localhost"到"*:80:custom.hostname"没有工作("坏主机名",即使正确等\主机映射),但"*:80:" 没有工作-与没有的这里的其他答案所需的其他步骤.请注意,"*:80:*"不会这样做; 留下第二个星号.
我试图将公共IP地址集成到我的工作流程中,这些答案没有帮助(我喜欢使用IDE作为IDE).但是上面的内容引出了我的解决方案(在将我的头撞到墙上大约2个小时后才能将其与Visual Studio 2012/Windows 8集成)这里最终为我工作了.
由VisualStudio生成的applicationhost.configC:\Users\usr\Documents\IISExpress\config
<site name="MySite" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\usr\Documents\Visual Studio 2012\Projects\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8081:localhost" />
<binding protocol="http" bindingInformation="*:8082:localhost" />
<binding protocol="http" bindingInformation="*:8083:192.168.2.102" />
</bindings>
</site>
Run Code Online (Sandbox Code Playgroud)
Administrator以便它可以绑定到外部地址(而不是本地主机)Administrator以便它可以作为管理员启动进程,从而允许绑定发生.最终的结果是你可以192.168.2.102在我的情况下浏览并测试(例如在Android模拟器中.我真的希望这有助于其他人,因为这对我来说绝对是一个令人恼火的过程.
显然这是一个安全功能,我很想看到残疾人.
小智 6
.vs\PROJECTNAME\config\applicationhost.config
将“*:44320:localhost”更改为“*:44320:*”。
<bindings>
<binding protocol="http" bindingInformation="*:5737:localhost" />
<binding protocol="https" bindingInformation="*:44320:*" />
</bindings>
Run Code Online (Sandbox Code Playgroud)
两个链接都有效:
现在,如果您希望应用程序使用自定义域,只需将以下行添加到主机文件中:
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 customdomain
Run Code Online (Sandbox Code Playgroud)
现在:
注意:如果您的应用程序无需 SSL 即可运行,请更改 protocol="http" 部分。
投票赞成的答案是有效的。.此信息对我有很大帮助。我知道之前已经讨论过该主题,但是我想添加一些其他输入。人们说您必须“手动编辑” Users IISExpress / Config目录中的application.config文件。这对我来说是个大问题,因为我想通过Source控件将配置分发给各个开发人员。
我发现您可以使用“ C:\ Program Files \ IIS Express \ appcmd.exe”程序自动更新此文件。找出控制参数花了一段时间,但我在这里分享了我的发现。本质上,您可以制作一个同时运行NETSH命令和APPCMD.EXE的.bat文件(如果需要,还可以换出一个主机文件),以使IIS Express的主机头配置变得容易。
您的安装bat文件如下所示:
netsh http add urlacl url=http://yourcustomdomain.com:80/ user=everyone
"C:\Program Files\IIS Express\appcmd.exe" set site "MyApp.Web" /+bindings.[protocol='http',bindingInformation='*:80:yourcustomdomain.com']
Run Code Online (Sandbox Code Playgroud)
我还将制作一个“卸载” bat文件,以清理这些绑定。.(因为通常我只是伪造DNS,以便我可以处理对主机名敏感的代码)
netsh http delete urlacl url=http://yourcustomdomain.com:80/
"C:\Program Files\IIS Express\appcmd.exe" set site "MyApp.Web" /-bindings.[protocol='http',bindingInformation='*:80:yourcustomdomain.com']
Run Code Online (Sandbox Code Playgroud)
我希望这些信息对某人有帮助。.我花了一些时间才发现。
像上面的Jessa Flint一样,我不想手动编辑.vs \ config \ applicationhost.config,因为我希望更改能够保留在源代码管理中。我也不想有一个单独的批处理文件。我正在使用VS 2015。
::The following configures IIS Express to bind to any address at the specified port
::remove binding if it already exists
"%programfiles%\IIS Express\appcmd.exe" set site "MySolution.Web" /-bindings.[protocol='http',bindingInformation='*:1167:'] /apphostconfig:"$(SolutionDir).vs\config\applicationhost.config"
::add the binding
"%programfiles%\IIS Express\appcmd.exe" set site "MySolution.Web" /+bindings.[protocol='http',bindingInformation='*:1167:'] /apphostconfig:"$(SolutionDir).vs\config\applicationhost.config"
Run Code Online (Sandbox Code Playgroud)
只需确保将端口号更改为所需的端口即可。
| 归档时间: |
|
| 查看次数: |
150036 次 |
| 最近记录: |