MVC4 Multiple Routes/ Multiple Domains and Sub Domains - General Exception - asp.net-mvc

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?

Related

Problems deploying mvc app to sub directory of site

When i place all my files in the root of my site, it overrides the existing site and automatically goes to the calendar application instead of the index.php that i have.
I have an existing site that i cannot change, so i was wondering how i can deploy this in a subdirectory, ex mysite.com\mvc_app\Home\Index
Here is my routing for the route config, any help would be appreciated! (i tried ignoring the blank route but it seems to open the app still, even tho hostbuddy is set to route mysite.com to the index.php as the default page)
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

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.

Deploy ASP.NET MVC on virtual directory

When i return View() from my action, result URL was not include virtual directory name.
expect for this
...../MyMVCApp/Controller/Action
but i got this
..../Controller/Action
How can i fix this problem?
Thank you in advance.
EDIT:
My RouteConfig.cs is
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Con", action = "Index", id = UrlParameter.Optional }
);
and on IIS(6.1) I just add application on the some root site like this
Website
|
|- MyMVCApp
|- OtherApp
This shouldn't be an issue at all as long as your virtual directory is a web application in IIS. If you have configured your project as a web app and you still have issues then it should be a routing problem.
By saying that, I believe your issue is IIS configuration or a routing problem. Can you paste a screenshot of your IIS structure and how you are registering your routes?

MVC routing requiring ".cshtml" in URL

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?

Using namespaces in RegisterRoute (MVC)

I have a solution with multiple projects. One of my projects only contains controllers. Another project contains my Views.
In my Views project, I've added namespaces in my RouteConfig.cs but I keep getting an error when I run my project:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.17929
This is my RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
namespaces: new[] { "AS.Core.Controllers" },
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
My HomeController.cs' namespace is namespace AS.Core.Controllers.Home
Setup:
Solution: AS.Core
-- Project: AS.Core.Controllers (controllers only)
-- Project: AS.Core.Web (views/scripts/css/images)
Under my controllers project I have multiple folders, such as "Home" and "Assets". I then have a controller in each folder so, I have "HomeController.cs" in the Home folder and "AssetsController.cs" in my Assets folder.

Resources