如何在IIS Express中启用远程请求?Scott Guthrie写道,这是可能的,但他没有说明如何实现。
当前回答
帮助我在dotnet core 6项目中允许远程访问我的IIS服务器的是在[解决方案目录]/Properties/launchSettings中设置项目的“applicationUrl”参数。将Json的值从“http://localhost:5000”更改为“http://0.0.0.0:5000”
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:20845",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyLittleProject": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "http://0.0.0.0:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
但正确设置防火墙以允许访问服务器的TCP端口也很重要:在我的例子中,添加了TCP端口5000的入站规则以允许连接。
其他回答
[项目属性对话框]
使用VisualStudio 2017和NetCore api项目进行开发:
1)在Cmd-Box: ipconfig /all中确定ip地址
2a)在“项目属性->调试”选项卡中输入检索到的ip地址
2b)选择一个端口,并将其附加到步骤2a中的ip地址。
3)在防火墙中添加allow规则,允许从所选端口进入tcp流量 (我的防火墙被一个对话框触发:“阻止或添加规则到防火墙”)。在这种情况下,加法就可以了。
上述方案的缺点:
1)如果你使用动态ip地址,你需要重做上述步骤,以防另一个ip地址已被分配。
2)你的服务器现在有一个开放的端口,你可能会忘记,但这个开放端口仍然是一个邀请不受欢迎的客人。
这是我用Visual Studio 2015为Windows 10启用远程访问所做的,包括http和https:
第一步是将应用程序绑定到内部IP地址。执行cmd -> ipconfig命令获取地址。打开文件/{项目文件夹}/.vs/config/applicationhost。配置并向下滚动,直到你找到像这样的东西:
<site name="Project.Web" id="2">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Project\Project.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:12345:localhost" />
</bindings>
</site>
在bindings下添加两个新绑定。如果你喜欢,你也可以使用HTTPS:
<binding protocol="http" bindingInformation="*:12345:192.168.1.15" />
<binding protocol="https" bindingInformation="*:44300:192.168.1.15" />
将以下规则添加到您的防火墙,以admin身份打开一个新的cmd提示符,并运行以下命令:
netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=12345 profile=private remoteip=localsubnet action=allow
netsh advfirewall firewall add rule name="IISExpressWebHttps" dir=in protocol=tcp localport=44300 profile=private remoteip=localsubnet action=allow
现在以管理员身份启动Visual Studio。右键单击web项目项目文件并选择属性。进入“Web”页签,单击“创建虚拟目录”。如果Visual Studio不是以管理员身份运行,则可能会失败。现在一切都正常了。
在我找到iisexpress-proxy之前,什么都没用。
以管理员身份打开命令提示符,然后运行
npm install -g iisexpress-proxy
then
iisexpress-proxy 51123 to 81
假设您的Visual Studio项目在localhost:51123上打开,并且您想在外部IP地址x.x.x.x:81上访问
编辑:我目前正在使用ngrok
这是非常棒的,甚至包括HTTPS的漂亮域名:
http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx
非常棒的部分,我在其他地方找不到,以防上面的链接消失:
> C:\Program Files (x86)\IIS Express>IisExpressAdminCmd.exe Usage:
> iisexpressadmincmd.exe <command> <parameters> Supported commands:
> setupFriendlyHostnameUrl -url:<url>
> deleteFriendlyHostnameUrl -url:<url>
> setupUrl -url:<url>
> deleteUrl -url:<url>
> setupSslUrl -url:<url> -CertHash:<value>
> setupSslUrl -url:<url> -UseSelfSigned
> deleteSslUrl -url:<url>
>
> Examples: 1) Configure "http.sys" and "hosts" file for friendly
> hostname "contoso": iisexpressadmincmd setupFriendlyHostnameUrl
> -url:http://contoso:80/ 2) Remove "http.sys" configuration and "hosts" file entry for the friendly hostname "contoso": iisexpressadmincmd
> deleteFriendlyHostnameUrl -url:http://contoso:80/
上面的实用程序将为您注册SSL证书!如果你使用-UseSelfSigned选项,这非常简单。
如果你想用困难的方式做事,不明显的部分是你需要告诉HTTP。SYS使用什么证书,像这样:
netsh http add sslcert ipport=0.0.0.0:443 appid={214124cd-d05b-4309-9af9-9caa44b2b74a} certhash=YOURCERTHASHHERE
Certhash是您可以从MMC中的证书属性中获得的“Thumbprint”。
结合这个帖子中的答案,这是我如何修复它(Visual Studio 2019):
以管理员身份启动Visual Studio,并像往常一样运行Web服务。 在任务栏上找到IIS Express图标,右键单击它,然后单击“显示所有应用程序”。 选择您的Web服务并注意下面显示的配置路径。单击配置文件以打开它进行编辑。 在这个配置文件中找到您的web服务(例如搜索您的端口),然后找到如下一行: *: yourport: localhost 在这之后添加新的一行,像这样: : yourport: *
在这种情况下,不需要使用将来可能会改变的特定ip地址创建绑定。
我希望这能帮助到一些人。
推荐文章
- ASP是什么?NET Identity的IUserSecurityStampStore<TUser>接口?
- net HttpClient。如何POST字符串值?
- 我如何使一个方法的返回类型泛型?
- 何时处理CancellationTokenSource?
- ASP。网网络。config: configSource vs.文件属性
- 如何获取正在执行的程序集版本?
- AutoMapper vs valueinjector
- 为什么控制台不。Writeline,控制台。在Visual Studio Express中编写工作?
- 什么是.NET程序集?
- 字符串不能识别为有效的日期时间“格式dd/MM/yyyy”
- 函数应该返回空对象还是空对象?
- 如何转换日期时间?将日期时间
- 如何在c#中连接列表?
- 在c#中引用类型变量的“ref”的用途是什么?
- 防止在ASP中缓存。NET MVC中使用属性的特定操作