Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host asp.net core app in IIS to access from other PC's inside the network

How can i host my Asp.Net Core (1, 2 or 2.1) web app in Windows IIS to be able to access it from other PC's in our local network (or my Virtual OS)? My PC is a Desktop Windows 10 Pro (not Win Server).

I have followed the Host ASP.NET Core on Windows with IIS article, but i can't get it to work.

What i did based on that article is as following:

Ensure Prequisites: Visual Studio 2017, Install Asp.Net Core 2.1 SDK, Add Internet Information Services (IIS) from Turn Windows features on or off, Asp.Net Core Hosting Bundle Installer from here (verified AspNetCoreModule module in IIS) and then:

Publish a default asp.net core app in Visual Studio (Build > Publish > Folder) to a folder and copy its contents to D:\publish1.

in IIS, right-click Sites > Add Website... and use these values (according to the picture shown there):

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

Also change Application Pools > mysite_com > Basic Settings > .Net CLR Version to No Managed Code.

Now, my web app can't be reached in browser when i tested http://[IP of my PC]/mysite.com or similar addresses.

So, What's wrong with these IIS settings?

Edit: It seems that this is not specific to .net core 2.1 only (the instruction is mainly the same when you change the .net core version of article), so i modified the title and question.

like image 745
S.Serpooshan Avatar asked Jan 02 '23 04:01

S.Serpooshan


1 Answers

I found the solution and want to record it here as it may be helpful for other ones. Its interesting that the Microsoft doc does not explain all details for such a common scenario as when you want to run you web app in an intranet network like as building of a large office. Here is the required IIS settings:

  1. Ensure you have IIS (Turn windows features on or off > internet information services)

  2. Ensure Asp.Net Core Host Bundle is installed: dotnet-hosting-2.1.1.exe: AspNetCoreModule in IIS can be verified from IIS Manager > Web Sites > any website eg Default Website > Modules.

  3. Publish your asp.net core app in Visual Studio (Build > Publish > Folder) to a folder and then copy its generated files to other desired destination path (eg D:\publish1) to avoid file lock issues for next code updates.

  4. in IIS, choose Application Pools (from the left tree view above the Sites), right-click > choose Add Application Pool > Name: myAppPool, .Net CLR Version: No Managed Code. (for .Net Core Apps)

  5. Find your IP address: run ipconfig in the command prompt (in windows 10, it is under Ethernet adapter: IPv4 Address, eg: 192.168.103.xyz).

Now, there are two options: A) Add Website, or, B) Add Application inside Default Website

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

in IIS Manager, choose "Sites" node from the left tree view > right-click > Add Website... >

[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

  • The key settings you may miss here is the Port (other than 80) and Host name (empty string) as noted above! Check this link to know about different port numbers: System Ports (0-1023), User Ports (1024-49151), Dynamic/Private Ports not assigned usually (49152-65535).

  • You can set more than 1 port number or IP for your site: choose [Bindings] from the right panel and edit or add the entries.

  • Allow your chosen port number through your Firewall to be able to access it from external PC's. For windows firewall go to: Windows Firewall with Advanced Security > Inbound Rules > New rule > [Port] option, specify your port number > ...

  • browse: 192.168.103.xyz:890 (using your ip address and choosen port number). If you don't set specific IP for your site (ie All Unassigned) then you can also browse localhost:890 to see your app.

B) Add Application (inside Default WebSite) => http://192.168.103.xyz/myApp

  • in IIS Manager, choose "Default Web Site" from the left tree view, right click > Add Application > choose a name for [Alias]: (eg: myApp), [Application Pool]: Select:myAppPool as specified in step 4, [Physical path]: your publish path (eg: D:\publish1)

  • browse: localhost/myApp in a browser in your own PC to test if you see your web application.

  • browse: 192.168.103.xyz/myApp (using your IP address) if you want to get it from other PC's on the network or a virtual PC.

like image 57
S.Serpooshan Avatar answered Jan 21 '23 23:01

S.Serpooshan