1

I created an app with ASP.NET Boilerplate (ABP) using the Module Zero Core template (Angular and ASP.NET Core, except I'm using .NET Full Framework 4.x). It works fine when I do a standard deployment to IIS (Angular running on port 80, ASP.NET Web API running on port 21021). However, I'm running into trouble with the Swagger integration if I try to deploy the Web API to an IIS Application (similar to a virtual directory). Previous answers I found have not provided a solution to the problem.

For example, the URL of the IIS Application is http://example.com/myapi. Navigating to that URL should redirect to http://example.com/myapi/swagger, but it redirects to http://example.com/swagger instead, which doesn't exist. ServerRootAddress is set to http://example.com/myapi in appsettings.json. This may be due to the following code in HomeController of the Web.Host project:

public IActionResult Index()
{
    return Redirect("/swagger");
}

It appears to be hard-coded to the root of the web site, rather than using a relative path, but I'm not certain. If I modify the controller to use a relative path, the Swagger page will load, but I am not able to authenticate. It tries to navigate to http://example.com/api/TokenAuth/Authenticate instead of http://example.com/myapi/api/TokenAuth/Authenticate. Again, it is not using a relative path. Here is related code from abp.swagger.js:

xhr.open('POST', '/api/TokenAuth/Authenticate', true);

Is this a limitation of ABP or the Module Zero Core template, or is there some additional configuration I need to do in ABP, Swagger/Swashbuckle, or IIS to get this working? FWIW, the app is running on ABP version 3.8.

Joel Leach
  • 126
  • 9

1 Answers1

2

I ended up changing ABP template code to use relative paths where necessary.

HomeController.cs:

public IActionResult Index()
{
    return Redirect("~/swagger");
}

abp.swagger.js:

xhr.open('POST', '../api/TokenAuth/Authenticate', true);
...
xhrTenancyName.open('POST', '../api/services/app/Account/IsTenantAvailable', true);

More changes would be required in order to use SignalR.

A couple of changes were needed in the Angular app as well.

index.html:

<base href="/myvirtualpath/">

sidebar-user-area.component.html:

<img src="assets/images/user.png" width="48" height="48" alt="User" />
Joel Leach
  • 126
  • 9
  • I have created the solution from ABP boilerplate and my files are somewhat different from yours. I have not managed to beat the error of incorrect bundle paths for IdentityServer project. Neither I can see where it's set - somewhere deep in guts... :( – Alexander May 18 '20 at 19:32
  • @Alexander These changes were for ABP version 3.8. I'm not sure what is required for newer versions. – Joel Leach May 18 '20 at 22:04