Deploying a Blazor server .NET 5 application as a sub application to another .NET 5 application

NT 1 Reputation point
2022-03-16T20:36:50.093+00:00

I have a .NET 5 Blazor Server application with signalr integration and it works fine when hosted on its own but I want it to be used as "mywebsite.com/newapp" if "mywebsite.com" is the address of the main application. The folder for the newapp is located in a folder separate from the main application like "C:\inetpub\wwwroot\NewApp" and on its own app pool. The web.config for the sub-app is like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\newapp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

When I try to go to "mywebsite.com/newapp", the page keeps on spinning and doesn't load. I also have other .NET framework sub applications running on it but they run fine when I go to "mywebsite.com/otherapp".

Since I don't have the directory for the Blazor app under main app, I didn't make any changes to the <base href="~/"> in _Host.cshtml or add app.UsePathBase("/NewApp") in Startup.cs. I added webBuilder.UseKestrel(); webBuilder.UseIISIntegration(); webBuilder.UseStartup<Startup>(); webBuilder.UseIIS(); in my program.cs and it doesn't work either.

I have checked the logs in Event Viewer and there are no errors. I tried to upload the basic Blazor app without any signalr integration and that works. Is the sub-app structure unable to hit the signalr Hub class?

Is there anything I am missing?

Internet Information Services
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,672 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce Zhang-MSFT 3,766 Reputation points
    2022-03-17T07:02:07.37+00:00

    Hi @NT ,

    You need to add a href in index.razor. Change @page "/" to @page "/newapp/". Then you can get a page from IIS.

    183995-1.png

    However, you'd better not do that. It will cause more issues which are difficult to find a great solution. Because the application contains blazor route, signalr route and IIS route. If you add more functions and url paths to the example app in the documentation, if one of them fails, you will have a hard time troubleshooting which route is causing the problem.

    The best choice is setting it as a site on IIS, not sub application under site.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Bruce Zhang


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.