Routing Template results in a 404 when navigating to English /en/ site - .net-core

I have one basic routing template on my newly created project (.NET Core 2.2) (below).
routes.MapRoute(
name: "default",
template: "{parameter}/{controller}/{action}/{id?}"
);
If I try to go to localhost:5000/en/default/index it is not working (I get a 404). Something except "en" is working properly like localhost:5000/abc/default/index or localhost:5000/xyz/default/index.
Why is this happening? How can I fix it?

When I try to run my web app on IIS Express, it automatically adds configuration to applicationhost.config which is located at {SolutionFolder}\\.vs\\{SolutionName}\\config\\applicationhost.config. And it has virtual directories starting with "/en/". I don't know why IIS Express adds this virtual directories but that was the actual redirection problem.

Related

Problems deploying a mixed asp.net-core/ SPA application to IIS

Deploying my web app, I can't get my apis working. Everything works fine in development on my machine.
I have an SPA front and a asp.net back. I hit publish and I get the following folder structure.
publish
|-MyProj.dll
|-MyProj.exe
|-web.config
|-wwwroot
|-assets
|-all my spa.js
|-index.html
I deploy all of that into the root of a new IIS application underneath Default Web Site.
When I browse to http://my-server/MyAppName/, my spa index.html is served, and that side is all fine. However, when the spa starts emitting api requests to http://my-server/MyAppName/api/some-route, the route is not resolved and IIS defaults to returning my index.html.
In my controllers, I use attribute routing... [Route("api/some-route")]. Just to test, I tried modifying a route attribute to [Route("MyAppName/api/some-route")] but I still get index.html. I know my Startup.cs is being processed because if I rename index.html in the code below, everything breaks and I don't see my spa anymore...
// Startup.cs
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "api/{controller}/{action=Index}/{id?}");
endpoints.MapFallbackToFile("index.html");
});
What do I need to configure to tell my app that it's in a virtual dir, and that requests to virtual-dir/api are to be served by asp ??????

Cannot find Account/Authorize when MVC Web App

I have an MVC app having the following default routing map:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Startup", action = "Index", id = UrlParameter.Optional }
);
As long as I deploy this site to the root of my IIS server (c:\inetpub\wwwroot) and create a new website within IIS, everything works just fine.
However if I create a directory within the wwwroot folder structure, deploy the same files there and instead of creating a website, I create an Application underneath the DefaultWebSite and point it to the subfolder where the files reside (c:\inetpub\wwwroot\MyApplication); when I launch the WebApplication that previous was configured as a website, I get the error "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Requested URL: http://localhost:80/Account/Authorize?client_id=web&response_type=token&state=
Physical Path: C:\inetpub\wwwroot\Account\Authorize
So it would appear that my routing needs to be adjusted to reflect the location of the app is in a subdirectory under wwwroot and not in wwwroot where it is looking.
What provisions should be taken to ensure an MVC Web "Application" runs properly under a Parent website?
=================================
UPDATED OBSERVATIONS
After considering a posted comment, I found a few more details of my issue may be noteworthy to mention.
My application is redirecting to the requested URL I posted by default, I am not doing it. In other words, if I open IIS, right-click my application under the DefaultWebSite and select browse; I am getting the incorrect URL. I don't ever recall having this issue with ASP.NET applications which suggests to me "routing" problem
If I alter the URL so that the Application Name precedes the Account/Authorize path I get redirected again to http://localhost/#access_token=&token_type=bearer&expires_in=1209600 and receive a blank content page that says "Beginning Execution" in the upper right hand corner. The title of the page says CORS Detection Script. Suggesting to me that my application possibly resides in a different domain that the default website??? Need some clarity on this though.
If I again precede the URL that landed me on the CORS Detection Script page with the Application Name, my page successfully loads as I'd expect
================================================
So again, I believe there are some adjustments required somewhere within my app (probably within the routing configuration) to compensate for the incorrect URL being generated by default.
Because if I setup the application as a website with all content at the root instead of a subdirectory, everything works.
Surely someone has seen this before
When you're creating an application in a subfolder of your website, you're effectively only changing the scope of the process running your app (w3p.exe). You will still need to put the application name in the url, like this:
http://localhost:80/MyApplication/Account/Authorize?etc

ASP.NET MVC Routing not Working in Virtual Directory

I have an asp.net mvc 2 app (using .net 4.0) that isn't routing correctly when hosted in a virtual directory. I have the following simple routing rule:
routes.MapRoute(
"Default", // Route name
"{action}", // URL with parameters
new { controller = "accounts" } // Parameter defaults
);
I'm trying to resolve http://mydomain.com/accounts/new. Where "accounts" is a virtual directory. If I put the app in the root of an IIS website it routes fine for http://mydomain.com/new, but if I put the app in a virtual directory I get 404 errors. I've debugged and it is executing global.asax and configuring routing when in the vdir. Is there something special I need to do for routing in a virtual directory?
FYI. I'm using a vdir because the root has wordpress in it.
Thanks!
one more thing is that if I specify a default action in parameter defaults, it will execute the default action/controller, but it never matches anything else.
I figured it out. Wordpress (which I had installed at the website root) had configured some URL rewrite rules which were preventing asp.net mvc receiving any requests other than the virtual directory root. Anything with a path beyond that was being rewritten to index.php which of course didn't exist in my mvc app.
I removed the rewrite rule, and now everything works as expected.
does it work if you change it to:
routes.MapRoute(
"Default", // Route name
"accounts/{action}", // URL with parameters (BUT WITH ACCOUNTS PREFIX)
new { controller = "accounts" } // Parameter defaults
);

Wildcard application map causing error on umbraco homepage

I'm trying to setup my umbraco site so that it does not use the .aspx extension. I made the necessary changes to the config files, but when I added the wilcard application mapping in IIS the homepage now comes back with an object reference error (at System.Web.UI.Control.ResolveClientUrl) if I try to access it from at the root (i.e. http://site.com/). The error doesn't occur if I add the default.aspx or if I browse to /home (the root node). Is there something else I need to setup to get the root node to run at the root url?
This is actually a problem with asp.net rather than merely umbraco - I found the answer on a DotNetNuke forum. The ResolveClientUrl function cannot handle a '/' URL. This was fixed by installing the latest service pack for asp.net 2.0.

asp.net mvc: page can not found

I'm trying to setup the MVC development enviroment on my laptop. I'm running WinXP Pro with IIS 5.1
I got the environment setup with the sample MVC application that come with beta. I can only get to the home page. when i try to open About us page. i run into the page can not be found error. Is it the routing not set in the Global.asax?
Your issue is that IIS 5/6 don't play nice with routes without extensions, the home page is resolving because its pointing to default.aspx,
In a nutshell, do this:
If *.mvc extension is not registered to the hosting , it will give 404 exception. The working way of hosting MVC apps in that case is to modify global.asax routing caluse in the following way.
routes.Add(new Route("{controller}.mvc.aspx/{action}",
new MvcRouteHandler())
{ Defaults = new RouteValueDictionary (new{ controller = "YourController"} ) });
In this way all your controller request will end up in *.mvc.aspx, which is recognized by your hosting. And as the MVC dlls are copied into your local bin , no special setttings need to be done for it.
See this question for lots of good information:
ASP.NET MVC and IIS 5
You may go to your IIS site's properties, tab "Home directory", press "Configuration...", select ".aspx", press "Insert...", Type "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll", uncheck check box and press "Ok". This heplped me.
Url rewriting can help you to solve the problem. I've implemented solution allowing to deploy MVC application at any IIS version even when virtual hosting is used.
http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx

Resources