11

I have a blazor server-side app hosted on IIS behind a reverse proxy (using ARR).

I have tried everything I can think of, but I keep getting 404 on

_framework/blazor.server.js

My base href is is set to "/subsite/":

<base href="/subsite/" />

and all my src values are relative like this:

<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorInputFile/inputfile.js"></script>
<script src="animations.js"></script>

Every other script ref loads fine, EVEN the _content data, but not the blazor.server.js.

I tried the old PathBase trick for MVC apps as well with no success:

if (!env.IsDevelopment()) {
    app.Use((context, next) => {
        context.Request.PathBase = new PathString("/subsite");
        return next();
    });
}

Can anyone tell me how to make Blazor realize where to put the blazor.server.js in a reverse proxy scenario?

3
  • 1
    blazor.server.js is a embedded resource. you can try getting a copy of the file and statically serving it like any other js file. But even then there is lot of signal-r chatter between the server and the browser. Not sure how its going to work in your setup. Commented Oct 29, 2019 at 3:23
  • Hmm. I don't really understand that, cause the components are embedded resources too, living in _content, but it finds them just fine. I'll try grabbing it and serving it statically, but this seems like an actual bug - I mean, how can you forget to support reverse proxy subsites in 2019 Commented Oct 29, 2019 at 7:46
  • Do you have any logging available to see which (and if) request path ends up with ASP.NET ? Commented Nov 10, 2019 at 12:40

2 Answers 2

2

Did you try the UsePathBase ?

app.UsePathBase("/subsite");

Here is my test result

test result

Please check this article for more https://www.billbogaiv.com/posts/net-core-hosted-on-subdirectories-in-nginx

Sign up to request clarification or add additional context in comments.

Comments

-1

From docs.

Rewrite URLs for correct routing

Routing requests for page components in a Blazor WebAssembly app isn't as straightforward as routing requests in a Blazor Server, hosted app. Consider a Blazor WebAssembly app with two components:

  • Main.razor – Loads at the root of the app and contains a link to the About component (href="About").
  • About.razorAbout component.

When the app's default document is requested using the browser's address bar (for example, https://www.contoso.com/):

  • The browser makes a request.
  • The default page is returned, which is usually index.html.
  • index.html bootstraps the app.
  • Blazor's router loads, and the Razor Main component is rendered.

In the Main page, selecting the link to the About component works on the client because the Blazor router stops the browser from making a request on the Internet to www.contoso.com for About and serves the rendered About component itself. All of the requests for internal endpoints within the Blazor WebAssembly app work the same way: Requests don't trigger browser-based requests to server-hosted resources on the Internet. The router handles the requests internally.

If a request is made using the browser's address bar for www.contoso.com/About, the request fails. No such resource exists on the app's Internet host, so a 404 - Not Found response is returned.

Because browsers make requests to Internet-based hosts for client-side pages, web servers and hosting services must rewrite all requests for resources not physically on the server to the index.html page. When index.html is returned, the app's Blazor router takes over and responds with the correct resource.

When deploying to an IIS server, you can use the URL Rewrite Module with the app's published web.config file. For more information, see the IIS section.


Maybe you could try to enable the forward proxy in IIS manager->server node->application request routing cache->proxy->enable.

If you only have one website, you could just add the website to ARR server farm and then it will create the routing rule automatically. It will be convenient to monitor the back-end server with health check.

Is this ARR warning causing my 404?

1 Comment

Well, as far as I can see - that article revolves around Blazor WebAssembly, and I'm using server side. Moreover, my IIS is already using the forward proxy feature of ARR (as this is how I'm doing reverse proxy in my setup).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.