Search code examples
iisblazorhost

Unable to host Blazor application


I am unable to get a Blazor app working while hosting the application as an IIS application on my local Windows 10 machine. The app is very simple, with just one page with minimal components - even simpler than the default Blazor app provided.

These are my steps:

  • Click on publish app
  • Select Folder, note it's going to ...\bin\Release\net5.0\browser-wasm\publish\
  • Open IIS, navigate to Default Web Site
  • Right-click Default Web Site and select Add Application
  • Select physical path as the path above, and host at www.NAME.com
  • Click Browse.. to view the app at www.NAME.com on *:80
  • Page displayed is the welcome page of IIS

Attempted Solution 1: Install URL Rewrite

Attempted Solution 2: Go to Hosts (in System32) and tried adding 127.0.0.1 or 127.0.0.1::80 followed by www.NAME.com

Attempted Solution 3: In index.html, edit the base element to include the link <base href="/NAME/" />

Attempted Solution 4: Instead of adding an application under Default Website in IIS, add it as a website instead

Attempted Solution 5: Gave IIS_IUSRS full permissions to web.config (Image)

None of the attempted solutions worked. I just started using Blazor yesterday and I am very new to this. Am I doing something wrong? Thank you!


Solution

  • Please refer to this tutorial, I think is one of the best tutorial to achieve your goals: https://blog.medhat.ca/2020/08/deploy-client-side-blazor-web-api-to.html?m=1

    Remember that the configuration of the hostname in your hosts file is related to your machine only

    So, in order to allow the students to access your IIS published site you need:

    1. Register a hostname in a DNS server that all the computer of the students will use to resolve your machine name. I.e. if your machine should be accessible with www.name.com you need your DNS server resolves this name with your local IP address
    2. To use the https protocol you need a certificate on your local machine, loaded in your IIS configuration, but the same certificate has to be available to every computer of your students.

    I think the better and simpler solution is to use your local machine name, probably using your full DNS name, and allows the students to access the site using this name on their browser.

    In this case you can use your local development certificate to allow https connection This certificate is already installed on your machine for development purpose.

    Every concept I've described is well documented on the web and here on the SO.