我找到了解决方案,想把它记录在这里,因为它可能对其他人有帮助。有趣的是微软
doc
不会解释这样一个常见场景的所有细节,例如当您希望在内部网网络(如构建大型办公室)中运行Web应用程序时。以下是所需的IIS设置:
-
确保您有IIS(打开或关闭Windows功能>Internet信息服务)
-
确保已安装ASP.NET核心主机捆绑包:dotnet-hosting-2.1.1.exe:IIS中的aspnetcoremodule可以从IIS管理器>网站>任何网站(如默认网站>模块)进行验证。
-
在Visual Studio中将ASP.NET核心应用程序(build>publish>文件夹)发布到某个文件夹,然后将其生成的文件复制到其他所需的目标路径(例如d:\ publish1),以避免下次代码更新时出现文件锁定问题。
-
在IIS中,选择“应用程序池”(从站点上方的左树状图中),右键单击>选择“添加应用程序池”>名称:myapppool,.net clr版本:无托管代码。(用于.NET核心应用程序)
-
查找IP地址:运行
ipconfig
在命令提示符下(在Windows 10中,位于以太网适配器下:
IPv4 Address
,例如:192.168.103.xyz)。
现在,有两个选项:a)添加网站,或b)在默认网站内添加应用程序
a)添加网站
=>
http://192.168.103.xyz:890
在IIS管理器中,从左树状图中选择“站点”节点gt;右键单击gt;添加站点…>
[Site name]: myApp
[Application Pool]: Select:myAppPool as specified in step 4. if you didn't create it in before, IIS will add a new pool based on your SiteName which you can edit its Basic Settings later in Application Pools tree view node to set its .Net CLR Version to No Managed Code.
[Physical path]: path to your published files (eg: D:\publish1)
[IP address]: can change it to your IP (from drop down) or left it to `All Unassigned`
![Port]: must be something other than 80! (eg: 890), it must be a free port not taken by other apps. you can test different values if some fails. in my case, port 4, 100, 200, 1100 works; but 80, 110 (pop3 email) or 3000 not works as they are used/reserved for other means.
![Host name]: left it blank if you want to access this app from your network! It is required for real internet world wide web sites!
-
您可能错过的关键设置是
端口(80除外)
和
主机名(空字符串)
如上所述!支票
this link
了解不同的端口号:系统端口(0-1023)、用户端口(1024-49151)、通常未分配的动态/专用端口(49152-65535)。
-
可以为站点设置多个端口号或IP:从右侧面板中选择[绑定],然后编辑或添加条目。
-
允许您选择的端口号通过
防火墙
才能从外部PC访问。对于Windows防火墙,请转到:
Windows Firewall with Advanced Security > Inbound Rules > New rule > [Port] option
,请指定端口号>…
-
浏览:192.168.103.xyz:890(使用您的IP地址并选择端口号)。如果你没有为你的站点设置特定的IP(即
All Unassigned
)然后,您还可以浏览localhost:890以查看您的应用程序。
b)添加应用程序
(在默认网站内)=>
http://192.168.103.xyz/myApp
-
在IIS管理器中,从左树状图中选择“默认网站”,右键单击“添加应用程序”>为[别名]:(例如:myapp),[应用程序池]:选择步骤4中指定的:myapp pool,[物理路径]:发布路径(例如:d:\ publish1)
-
browse:localhost/myapp,在您自己电脑的浏览器中测试您是否看到了您的web应用程序。
-
浏览:192.168.103.xyz/myapp(使用您的IP地址),如果您想从网络上的其他PC或虚拟PC获取它。