Reputation: 121
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.
Upvotes: 10
Views: 12489
Reputation: 309
If you want to do this just to test on other devices on the LAN, you can actually just use Kestrel directly to serve the Blazor pages, but it won't work over https. See the microsoft docs on this subject
That said, you can simply add http://*:5000
(or whatever other port you want) to the applicationUrl
property on the Properties/launchSettings.json
file.
Then the next time you run the project, windows may ask you if you want to allow connections to the app (allowing access to go through the firewall), just press Allow
. You should now be able to access it on any device on the LAN.
the launchSettings.json
file may end up looking something like this:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://*:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Upvotes: 2
Reputation: 2888
In my case I've added the entry https://*:5001
in the file launchSettings.json
as could be seen in this answer
Upvotes: 3
Reputation: 121
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"
Upvotes: 1
Reputation: 5865
Here is a blog article where the problem is explained, basically there are the following steps needed:
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");
});
Upvotes: 0