如何在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的入站规则以允许连接。
其他回答
帮助我在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的入站规则以允许连接。
这是我用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
我已经启用了本地IIS,所以我刚刚创建了一个重写规则到我的调试端口…我认为这比其他方法更好,更酷,因为它更容易删除一旦我完成开发…下面是重写的样子。
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^dev/(.*)" />
<action type="Rewrite" url="http://localhost:47039/{R:1}" />
</rule>
</rules>
</rewrite>
VS也允许你直接使用本地IIS进行开发(然后允许远程连接),但是反过来你必须总是以管理员身份运行它…我不喜欢那样。
我发现最简单最酷的方法是使用(设置需要2分钟):
https://ngrok.com/
它将与本地主机上运行的任何东西一起工作。只要注册,运行小可执行程序,不管你在localhost上运行什么,你都可以从任何地方访问公共URL。
这对于向远程团队成员显示内容很有好处,无需摆弄IIS设置或防火墙。要停止访问只需终止可执行文件。
ngrok authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ngrok http -host-header=localhost 89230
假设89230是您的IIS Express端口
您也可以运行多个端口,甚至在免费计划
推荐文章
- 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
- 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
- 如何使用JSON确保字符串是有效的JSON。网
- AppSettings从.config文件中获取值
- 通过HttpClient向REST API发布一个空体
- 如何检查IEnumerable是否为空或空?
- 自动化invokerrequired代码模式
- 在c#代码中设置WPF文本框的背景颜色
- 在c#中,什么是单子?
- c#和Java中的泛型有什么不同?和模板在c++ ?
- c#线程安全快速(est)计数器
- 如何将此foreach代码转换为Parallel.ForEach?
- 如何分裂()一个分隔字符串到一个列表<字符串>
- 如何转换列表<字符串>列表<int>?
- c#对象列表,我如何得到一个属性的和