Home > Mobile >  Blazor Server App Uses Wrong URL For CSS Files
Blazor Server App Uses Wrong URL For CSS Files

Time:04-20

I have created a simple Blazor Server app with VS2022. I just used the default example code and made no changes. The application is then run on my server, where I can access it via https://myserver/myapp (a IIS redirect redirects that to http://localhost:5000).

The problem now is that the app cannot find any of the CSS files. E.g. it tries to load "https://myserver/css/site.css", which does not exist. The correct path would be "https://myserver/myapp/css/site.css".

How can I change the path where the Blazor app looks for its files?

CodePudding user response:

The correct path would be "https://myserver/myapp/css/site.css".

When you had installed it as a regular IIS WebSite then it would have worked 'out of the box'. But with a IIS redirect things could fall apart.

Your best option now is to change the base href in _Layout.cshtml to

<base href="~/myapp/" />
  • Related