-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor Web App Template - website after publish to local IIS fails to load #50032
Comments
@Lindsay-Mathieson ... More config might be required, but start by updating the app's base path in the |
Thanks, that did the trick. Set it to: <base href="/BlazorWebAppTest1/" /> the default was Kinda awkward to customise that for each publish though, especially if you test with multiple websites/appnames. Is there a way to fill it in with the publish web site appname? |
I'm glad it worked cleanly with just an app base path change. BTW, that's covered at ... ... but I haven't reached that node of documents yet for content updates that will include Blazor Web Apps. I'll get there eventually tho. 🏃🏃🏃😅 WRT a transform for that element, no ... I'm not aware of one that would configure it for publish. However, the root component ( @inject IHostEnvironment Env
<!DOCTYPE html>
<html lang="en">
<head>
...
<base href="/@appBasePath" />
...
</head>
...
</html>
@code {
private string appBasePath;
protected override void OnInitialized() =>
appBasePath = Env.IsStaging() ? "staging/" : string.Empty;
} ... and it rendered ... <base href="/staging/" /> ... for the Staging environment 🎉. Therefore, you could take that approach forward for your process. †seems: I'm just a hack 🦖 doc author around here 🙈😆, so we'll need to see if the engineering 🐈🐈🐈 have any caveats on that approach or further/different remarks. They're probably all off for the weekend, so you'll probably hear back next week. Setting the environment is covered in https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0. Using an env var, the |
... and I think it's a bit cleaner (less code, no hard-coded string) to obtain the value from config, so I'll probably end up writing it up along the lines of ...
{
"AppBasePath": "staging/"
} @inject IConfiguration Config
...
<head>
...
<base href="/@(Config.GetValue<string>("AppBasePath"))" />
...
</head> It doesn't throw if the value is null (i.e., missing the config value). It results in a I didn't care much for using the environment value itself with coordination on the folder name because it wouldn't be common to have the environment name in the URL, but there might be an edge case for it if only the Staging environment requires the treatment with Development and Production environments using " @inject IHostEnvironment Env
<head>
...
<base href="/@(Env.EnvironmentName != "Development" ? $"{Env.EnvironmentName}/" : string.Empty)" />
...
</head> ... for the Staging environment ... <base href="/Staging/" /> |
Thanks for answering this, @guardrex! 🎉 |
Is there an existing issue for this?
Describe the bug
Created a Blazor sample application using the new Blazor Web App template - .Net Preview 7, Visual Studio Preview with Preview 7 hosting installed.
Runs fine via Visual Studio. When I published it to my local IIS via VS Web Deploy, the website failed to load/display correctly, with a bunch of 404 errors for the .css files displayed in Edge DevTools. It appears to be referencing the css from the "http://localhost", rather than "http://localhost/appname"
nb. It does work correctly if published to the root of the IIS Website
Expected Behavior
The website to display as it does when run from Visual Studio
Steps To Reproduce
Sampe Repository:
https://github.com/Lindsay-Mathieson/BlazorWebAppTest1
Exceptions (if any)
No response
.NET Version
8.0.100-preview.7.23376.3
Anything else?
.NET SDK:
Version: 8.0.100-preview.7.23376.3
Commit: daebeea8ea
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\
.NET workloads installed:
There are no installed workloads to display.
Host:
Version: 8.0.0-preview.7.23375.6
Architecture: x64
Commit: 65b696cf5e
RID: win-x64
.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
7.0.400 [C:\Program Files\dotnet\sdk]
8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-preview.7.23376.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
The text was updated successfully, but these errors were encountered: