Skip to content
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

Routing issue when using "UsePathBase" #1868

Closed
devzaak opened this issue Oct 20, 2020 · 2 comments
Closed

Routing issue when using "UsePathBase" #1868

devzaak opened this issue Oct 20, 2020 · 2 comments
Labels
responded Responded with solution or request for more info

Comments

@devzaak
Copy link

devzaak commented Oct 20, 2020

Using:
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.1" /> in
netcoreapp3.1

With setup:

// part of the Configure in startup with IApplicationBuilder builder
// serviceOptions.BasePath resolves to "/SomePath"
builder.UsePathBase(serviceOptions.BasePath); 

builder.UseRouting()
    // Swagger routing needs to occur before authentication/authorization otherwise it will result in 401 Unauthorized
    .UseSwagger(options => options.RouteTemplate = "/swagger/{documentName}/swagger.json")
    .UseSwaggerUI(options =>
    {
        // When a base path has been set ensure the swagger endpoint includes it, otherwise the redirects will go to the
        // wrong location and no help will be visible
        options.SwaggerEndpoint($"{serviceOptions.BasePath}/swagger/v1/swagger.json", "API v1");
        options.RoutePrefix = "help";
    })

I am running into a strange problem:
I get access to the swagger UI on urls:
http://localhost:8080/SomePath/help/index.html
http://localhost:8080/help/index.html

but when trying to go to http://localhost:8080/SomePath/help
redirect happens to http://localhost:8080/SomePath/SomePath/help/index.html
and of course it hits 404

Any idea what is the cause of this reroute?
Thanks

@domaindrivendev
Copy link
Owner

I recall a lot of back and forth in this part of the code and so can't be sure when this exact issue was fixed, but I just tested this myself with the latest code and it appears to work as expected. I'm working hard to get a 6.0.0 release out next week but in the meantime you can pull down the latest perview build from myget.org and try it out. Be sure to clear the browser cache first.

@domaindrivendev domaindrivendev added the responded Responded with solution or request for more info label Jan 18, 2021
@devzaak
Copy link
Author

devzaak commented Jan 18, 2021

Nice, I can confirm it was resolved, I think that fix happened with this change:
31c561d

thanks

@devzaak devzaak closed this as completed Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
responded Responded with solution or request for more info
Projects
None yet
Development

No branches or pull requests

2 participants