How can I run a Blazor App from another device on my local network?

Viewed 3910

I just ran through crating my first Blazor App. I can run and also debug in Vs Code and Visual Studio using Chrome or Edge. Now I would like to run the app on other devices on my LAN. I created a rule for port 5001 in Windows Firewall but I am unable to access my app using my PC's IP address from other devices on my local network. This is something I have been able to do with other stacks. Am I missing some configuration step? Thanks.

3 Answers

Here is a blog article where the problem is explained, basically there are the following steps needed:

  • Open your firewall on the specific port
  • Specify your IP-address or 0.0.0.0 for all available IP-addresses in Program.cs:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                //webBuilder.UseUrls("https://192.168.120.112:65437");
            });
    
  • Run the project with Kestrel and not IIS-Express

I tried the suggestion above but was not able to get it to work. I finally got the functionality I wanted with ngrok using the command below.

ngrok http https://localhost:5001 -host-header="localhost:5001"

Related