I have an ASP.NET Core 2.1 WebAPI project with Swashbuckle.AspNetCore 3.0.0. It has a domain xx.xx.com and a dynamic subdomain /something rewritten to / in my reverse proxy.
I've configured the UI to use a relative path with:
c.SwaggerEndpoint("v1/swagger.json", "MY API V1");
The problem is the methods are called in the root of the domain instead of with a relative path and I get error 404 for all "Try it out"s.
It calls xx.xx.com/method instead of xx.xx.com/something/method.
Is there a way to overcome this issue without changing the reverse proxy behavior?
Related
I'm trying to deploy my web api behind nginx.
My web API is always start with http://<host>/api/<controllerName>
But I use Nginx reverse proxy to handling test and prod server request
The request to test server http://<host>/api/<controllerName>/<action> turn to http://<host>/test/api/<controllerName>/<action>
Everything is OK so far except I use RedirectToActionResult in some action. It still redirect to url to http://<host>/api/<controllerName>/<action> format. Is there any way I could adjust RedirectToActionResult to redirect with prefix like http://<host>/test/api/<controllerName>/<action>?
Or I have to modify the whole API server url with prefix path.
You can set ASPNETCORE_PATHBASE=/test in your Environment.
And in your Startup.cs, you can add below code.
var pathBase = Environment.GetEnvironmentVariable("ASPNETCORE_PATHBASE");
app.UsePathBase(new PathString(pathBase))
Related Post:
ASP.Net Core Reverse Proxy with different root
I have a similar requirement which is mentioned in the link Dots in URL causes 404 with ASP.NET mvc and IIS . Our requirement is, we also do have URLs with dots in the path. For example I may have a URL such as www.example.com/people/michael.phelps (This example is taken from above link)
URLs with the dot generate a 404. If we pass without the dot, then everything works. If we add the dot I get a 404 error.
The above link provide solution for earlier versions of .net where we can have webconfig files. But we are using .net core to build web API application. Dotnet core does not support webconfig files. Can someone please suggest how can we arrive at the solution by using .net core.
Late answer but we had a similar case:
We had a url looking like https:/domain.com/somepath/smoething.cd
This returned a 404 from the IIS. Adding a / at the end of the url behind the .cd fixed the issue.
Strange but notable: not all.something return a 404, .com at the end of the path for example works
I am working on a project which has subdomains like:
'example.com', 'app.example.com' and 'admin.example.com'
and iis is acting like each subdomain is like an app.
iis snapshot.
I want to use SignalR under the sub domain 'app' but could not achieve. Installed the packages:
"Microsoft.AspNetCore.SignalR.Server": "0.2.0-*"
"Microsoft.AspNetCore.WebSockets": "0.2.0-*"
It worked under 'example.com' but not under 'app.example.com'
Got 404 error while trying to find the src 'signalr/hubs'.
How can I route the signalr to my subdomain 'app'.
Best regards
"Microsoft.AspNetCore.SignalR.Server": "0.2.0-*" is dead. Don't use it. SignalR for Asp.NET Core version is developed here. It's very early though and things keep changing rapidly.
In Startup.cs configure method when setting cookie authentication options the login path in the examples seem to reference a web root path.
https://docs.asp.net/en/latest/security/authentication/cookie.html
What if I am deploying the app in a virtual directory and do not want to hardcode it?
I could add the virtual directory to a config file but it seems like a step backwords. When I had similar issues before it seemed like i could use Url.Action or the VirtualPathUtility. Is there something similar in asp.net core that can be used in startup.cs?
I am using ASP.NET MVC4 with WinHost.
Just like the question asked here, I ran into the same issue:
I'm trying out WinHost and I'm running into some issues with
sub-domains. On WinHost, you can have multiple sub-domains per hosting
account, but each sub-domain points to the root website. E.g. you can
have www.example.com, sub1.example.com, and sub2.example.com but all
of them display the content at http://www.example.com/.
Other Hosts allow you to point sub-domains to a sub folder in your
website. This would allow you to point sub1.example.com to /sub1,
sub2.example.com to /sub2 and www.example.com to /.
WinHost recommends using an asp/aspx page to redirect
http://sub1.example.com to http://sub1.example.com/sub1, which points
to /sub1. While that would work, I'd like to not have the subdomain in
the url twice.
So I tried using IIS7 URL Rewrite to point http://sub1.example.com to
/sub1. Ben Powell describes this in detail on his blog.
I've managed to get this portion to work so that http://sub1.example.com actually points to my virtual application "/sub1" in IIS.
If I use Url.Content, it works flawlessly.
Now, I am using ASP.NET Optimization and I bundle scripts and css. Issue is that it absolutely require a relative url ie:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
However, because it's a relative url here is what I will get in the markup:
<script src="/sub1/bundles/jqueryval?v=UgyEMAYOuSB9Bb6HcOEVHpd6fIIp54yF086SRNVcdIY1"></script>
Of course, because of the "sub1" it doesn't find the file. I thought about URL Redirect that I never actually got to work. Maybe a route in MVC? Unsure how to do this as well. I could also drop the bundling alltogether to use "Url.Content" which I think is sad.
What would be the best way to handle this issue?
I know you can use IBundleTransform to modify contents in a bundle based on unique circumstances. You may be able to modify the bundle context itself. Here is a link MVC4 StyleBundle not resolving images