MVC routing requiring ".cshtml" in URL - asp.net-mvc

I have an MVC4 website running fine on dev. When trying to publish to production routing doesn't work. The only rule I have is the default:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "General", action = "Index", id = UrlParameter.Optional }
);
However, on production server (IIS7.5 - just like dev) any of the following fails on 404:
<domain>/Home
<domain>/Home/Index
Plain <domain>/ fails on 403.
NOTE: All this while using route debugger
Playing around I stumbled upon the following curiosity:
<domain>/Home/Index.cshtml/3
Actually brought me to the route debugging page, claiming to match on
controller Home
action Index.cshtml
id 61
More playing showed that it doesn't matter where the ".cshtml" is, it works as long as it's there. e.g. <domain>/.cshtml/Index/4 matched
controller .cshtml
action Index
id 4
Why would it require a ".cshtml" string, and what can I do about it?

Related

MVC Site not working when published to web hosting provider

I am trying to publish an MVC site. The website/application are both setup for .NET Framework 4. When the site is published, the MVC page gives the following error:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Also if I try to bring up a test aspx file, I get this error:
"The resource cannot be found."
The first test I perform is to delete the web.config. At this point, I attempt to bring up an MVC page again and same error is displayed:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
However, if I try to bring up a test aspx page now, I actually get the page:
1 + 2 = 3
The test aspx page just contains this:
<html>
<body>
1 + 2 = <%=(1+2).ToString() %>
</body>
</html>
Any help of what to check next would be appreciated. Saw similar threads where it mentions of adding:
<customErrors mode="Off" />
and
<asp scriptErrorSentToBrowser="true"/>
But that still gives me the same error when bringing up a MVC page. Any help on how to proceed next to fix this MVC site would be appreciated. Thanks.
Update #1
I did a search for the keyword "routes.MapRoute" in the entire project and found it only once in the RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
The page I am testing is:
http://.../Home/Index
This is the page that returns:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I found the problem! The problem was that the website hosting provider had the website setup for IIS 6.0. In that case there are two options:
Update hosting site to support IIS 7.0. This was my solution and solved the problem
Set the MapRoute to run a "fake" aspx page: (only do this if you cant update hosting to IIS 7.0):
// IIS 6.0
routes.MapRoute(
name: "Default",
url: "typehereanything.aspx/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Using this second method is not recommended since now you have to plug in "typehereanything.aspx" into every URL: http://.../typehereanything.aspx/Home/Index
Any of those two options solved the issue.

mvc route cannot find conroller

I am following through with plural sight video messageboard app. it was working fine and suddenly routing is not finding the controller; i put break point on maproute function and it gets hit but from there i get not found error; also another problem is that i cannot see the error page ( call stack\ stack trace\ the horrible yellow page) it appears for a fraction of a second and then disappears.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
so please help me with both problems

MVC4 Multiple Routes/ Multiple Domains and Sub Domains - General Exception

Working on a MVC4 project where one of the domain has sub-domains and there are other 2 domains which should point to the same Global.asax.
All subdomains working fine but getting general exception when trying to open main domains
ex: www.pqr.com, www.mno.com (this has sub-domains)
ex: abc.mno.com, def.mno.com etc - these routes works ok
when i used Route Tester, all mappings seems ok
even Route Tester shows general exception. when we try to open www.pnr.com view opens with these special characters ��I�%&/m�{J�J��t��$ؐ#������
If we add domain name (www.pnr.com) to routes, request is not matching with url/route
sample route:
routes.MapRoute(
name: "www.pnr.com",
url: "{action}/{id}",
defaults: new { controller = "pnr", action = "home", id = UrlParameter.Optional },
namespaces: new string[] { "Controller.pnr" }
);
What are we doing wrong? How do we fix this?

Default Routing Not working in .NET MVC 1 (and 2)

My default routes are very simple, but the page doesn't properly load without fully qualifying the entire route.
Here are the routes I'm using:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
Here's the only action in the application in a HomeController:
public ActionResult Index()
{
return Content("New stuff");
}
With these URLs:
http://localhost:8081/NewMvc1/
I get The incoming request does not match any route.
With:
http://localhost:8081/NewMvc1/Home
http://localhost:8081/NewMvc1/Home/Index
I get a 404 Mvc page that says it tried to handle the request with a static file.
Yet, finally with a 'fully qualified url'
http://localhost:8081/NewMvc1/Home/Index/1
I get the expected result output from the one and only one action.
New Stuff
This doesn't seem right at all. I've also been getting Failed to Execute Action from this same application (not sure if that's related).
I've used Phil Haack's RouteDebugger to get this far, which pointed out that it wasn't matching the URL when the Optional parameters were missing, but did when those parameters were provided.
You're missing the id from your defaults:
new { controller = "Home", action = "Index", id = UrlParameter.Optional }

URL Routing: a link redirects when not followed by /

I have come across the most bizarre of problems: I have a login page in an MVC application, which when linked by /login will automatically redirect to the home page. However, if I use /Login or /login/, it works!
I have no idea whether it's something to do with a configuration I've messed up, or a configuration in the routing I've played around with, but it happens exclusively with the login page.
I am using forms authentication, and have tried changing the page that you're redirected to from the login page, but that doesn't seem to help at all.
Any ideas?
Update: this only happens on my local machine. I host with Windows Azure, and it works fine when deployed.
Edit: current routing configuration:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
);
routes.LowercaseUrls = true;
}

Resources