首页 文章

在IIS中托管asp.net核心应用程序,以便从网络内部的其他PC进行访问

提问于
浏览
0

如何在Windows IIS中托管我的Asp.Net Core(1,2或2.1)Web应用程序,以便能够从我们本地网络(或我的虚拟操作系统)中的其他PC访问它?我的电脑是台式机Windows 10 Pro(不是Win Server) .

我已经关注了Host ASP.NET Core on Windows with IIS文章,但我无法让它发挥作用 .

我根据那篇文章做的是如下:

确保先决条件:Visual Studio 2017,安装Asp.Net Core 2.1 SDK,从 Turn Windows features on or off 添加Internet信息服务(IIS),Asp.Net Core Hosting Bundle安装程序from here(在IIS中验证的AspNetCoreModule模块),然后:

将Visual Studio中的默认asp.net核心应用程序(Build> Publish> Folder)发布到文件夹,并将其内容复制到 D:\publish1 .

在IIS中,右键单击“站点”>“添加网站...”并使用这些值(根据显示的图片there):

[Site name]: mysite_com
  [Physical path]: `D:\publish1`
  [IP address]: `All Unassigned`
  [Port]: 80
  [Host name]: mysite.com

同时将 Application Pools > mysite_com > Basic Settings > .Net CLR Version 更改为 No Managed Code .

现在,当我测试 http://[IP of my PC]/mysite.com 或类似地址时,无法在浏览器中访问我的Web应用程序 .

那么,这些IIS设置有什么问题?

Edit: 这似乎并不是特定于.net核心2.1(当你更改.net核心版本的文章时,指令主要是相同的),所以我修改了 Headers 和问题 .

1 回答

  • 0

    我找到了解决方案,并希望在此记录,因为它可能对其他人有帮助 . 有趣的是,微软doc没有解释这种常见场景的所有细节,就像你想在内联网网络中运行web应用程序一样,如建造大型办公室 . 以下是必需的IIS设置:

    • 确保您拥有IIS(打开或关闭Windows功能>互联网信息服务)

    • 确保安装了Asp.Net Core Host Bundle:dotnet-hosting-2.1.1.exe:IIS中的AspNetCoreModule可以从IIS管理器>网站>任何网站验证,例如默认网站>模块 .

    • 将Visual Studio中的asp.net核心应用程序(Build> Publish> Folder)发布到文件夹,然后将其生成的文件复制到其他所需的目标路径(例如D:\ publish1),以避免下次代码更新时出现文件锁定问题 .

    在IIS中选择

    • ,选择应用程序池(从站点上方的左侧树视图),右键单击>选择添加应用程序池>名称:myAppPool,.Net CLR版本:无托管代码 . (适用于.Net Core Apps)

    • 找到您的IP地址:在命令提示符下运行 ipconfig (在Windows 10中,它位于以太网适配器下: IPv4 Address ,例如:192.168.103.xyz) .

    现在,有两种选择:A)添加网站,或者B)在默认网站内添加应用程序

    A) Add Website => http://192.168.103.xyz:890

    在IIS管理器中,从左侧树视图中选择“站点”节点>右键单击>添加网站...>

    [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!
    

    enter image description here

    • 您可能会错过的关键设置是 Port (other than 80)Host name (empty string) ,如上所述!检查this link以了解不同的端口号:系统端口(0-1023),用户端口(1024-49151),通常未分配的动态/专用端口(49152-65535) .

    • 您可以为站点设置多个端口号或IP:从右侧面板中选择[Bindings]并编辑或添加条目 .

    • 允许您通过 Firewall 选择的端口号能够从外部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) Add Application (默认网站内)=> http://192.168.103.xyz/myApp

    在IIS管理器中

    • ,从左侧树视图中选择“默认网站”,右键单击>添加应用程序>为[别名]选择一个名称:(例如:myApp),[应用程序池]:选择:步骤4中指定的myAppPool ,[物理路径]:您的发布路径(例如:D:\ publish1)

    • 在您自己的PC中的浏览器中浏览:localhost / myApp,以测试您是否看到了您的Web应用程序 .

    • 浏览:192.168.103.xyz / myApp(使用您的IP地址),如果您想从网络上的其他PC或虚拟PC上获取它 .

相关问题