This is for an ASP.NET MVC3 web application. In RegisterRoutes I have the following as my only line:
routes.MapRoute("Default", "Configuration", new { controller = "DeviceConfiguration", action = "Index" });
When I run the project, going to the URL /Configuration/ gives me a 404 error. However if I change the word Configuration to any other word, such as:
routes.MapRoute("Default", "Configuratio", new { controller = "DeviceConfiguration", action = "Index" });
Then going to the URL /Configuratio/ loads just fine. It seems as if ASP.NET is simply refusing to route to the URL /Configuration/.
Again, this is the only line in RegisterRoutes; I've tried commenting out everything else to debug this. I have no MapRoute or IgnoreRoute calls in my code anywhere else, and I am not editing the routing table in any location.
How can I change this behavior?
I suspect that you have a physical folder called Configuration under the root of your application. The ASP.NET MVC routing engine has preference for physical folders over routes. One possible way is to set the RouteExistingFiles property to true after your route definition:
routes.MapRoute(
"Default",
"Configuration",
new { controller = "DeviceConfiguration", action = "Index"
});
routes.RouteExistingFiles = true;
Related
My all ajax calls unexpectedly appending controller name twice in ajax calls by changing following line
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
to
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
I changed this line because i found a extra redirect, that first user will go to home and then from there he will be redirected to login page due to authorization failure. have a look at following console error
http://localhost:51381/Document/Document/GetCategoriesByDocumentType?categoryDocumentType=1&_=1480570187959
404 (Not Found)
as you can see that two controller name was appended.
/Document/Document/
My ajax call in separate Js file.
var url = 'Document/GetDocumentGrid?CategoryDocumentType=' +
CategoryDocumentType + '&categoryId=' + CategoryList + '&keywords=' +
search + '&isArchived=' + isArchived;
and when i revert route config , all ajax call works as expected.
what if i wanted my user to go on login page directly, instead of home? or i have to change all my ajax URL's ? And what is the reason of this behavior?
Note: i cannot use any Razor syntax as i have separate js files and i dont want to change every Js file, as my project goes almost 90 pages :(
I am converting an asp classic (.asp) to mvc4. The site is fine, but when I try to map the legacy pages to the new routes it fails big time.
I just want to : default.asp to / or pageA.asp to /NewPageA
When I try to map the old pages , looks like the asp classic handler intercepts first the request and try to find the page .asp, but as doesn't exist, it throws 404 error.
I am mapping wrong ? my mapping is like this:
routes.MapRoute("DefaultOld", "default.asp", new { controller = "Home", action = "IndexOld" });
routes.MapRoute("MenuOld", "menu.htm", new { controller = "Home", action = "IndexOld" });
routes.MapRoute("RecepcaoOld", "recepcao.htm", new { controller = "Home", action = "IndexOld" });
routes.MapRoute("EntradaPorOld", "entrada_por.htm", new { controller = "Home", action = "IndexOld" });
Is possible to tell the server to ignore the classic pages and let the mvc route to intercepts the request and act as it should ?
I am using IIS 7.
I tried this solution here (http://blog.abodit.com/2010/04/a-simple-redirect-route-handler-for-asp-net-3-5-routing/), works fine to map tp aspx pages, but when I try to use with asp or htm, it doesn't work at all. So I think I need t disable the handler od classic asp, is that correct ? but in the htm side, the StaticHandler if I disable it, the images and all static resources would not work well, correct ?
cheers
I'm want to host both WCF 4 and MVC 3 in my C#.Net project. But when I add the service paths for WCF, Html.ActionLink starts creating a wrong url for MVC app. My route table is created as:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.Add(new ServiceRoute("api1/projects", new WebServiceHostFactory(), typeof(Projects)));
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Above route table creates the right access paths to both the WCF and MVC applications, but Html.ActionLink creates the edit links as
http://localhost:8000/api1/projects?action=Edit&controller=technology&id=2
instead of
http://localhost:8000/technology/Edit/2
If I omit the line starting with RouteTable.Routes.Add, the ActionLink works as expected (and of course not the WCF). How can I add the WCF routes and make sure actionlink behaviour doesn't change?
Try putting ServiceRoute registration after MapRoute.
I have asp.net mvc project, and it's structure and routes are as below.
"Site.Master" include images and css files,with paths:
../../Images/1.gif
../../Content/site.css.
When visiting the page "http://www.localhost.com/Info/Index/1001", it works.
But page "http://www.localhost.com/Info/Index/1001/1" or "http://www.localhost.com/Info/Index/1001/2", don't.
I modified the images and css file path in the Site.Master like:
/Images/1.gif
/Content/site.css
In addition, is there another way to fix it? or modify routes? Because, i want deploy it using virtual directory in iis.
-> Images
1.gif
2.jpg
-> Content
site.css
-> Views
Home
-- index.aspx
Info
-- index.aspx
Shared
-- Site.Master
routes.MapRoute(
"InfoPagedRoute",
"{controller}/{action}/{classid}/{page}",
new { controller = "Info", action = "Index", classid = #"\d{1,10}", page = 1 }
);
Your original route:
routes.MapRoute(
"InfoPagedRoute",
"{controller}/{action}/{classid}/{page}",
new { controller = "Info", action = "Index", classid = #"\d{1,10}", page = 1 }
);
It looks like you are trying to use a validator in your route defaults for the classid, so either you need to include a validation parameter or set a default value for the classid.
I would suggest:
routes.MapRoute(
"InfoPagedRoute",
"{controller}/{action}/{classid}/{page}",
new { controller = "Info", action = "Index", classid = 1001, page = 1 }
);
If updating the route doesn't resolve the issue, you could use Phil Haack's route debugger. It is really helpful in figuring out if the route you are expecting to get hit is actually the one that is being used.
I create a new mhc application with razor data view engine. I have a problems with the url
Here is my action links
#Html.ActionLink("Home", "Index")
#Html.ActionLink("Schedule", "Schedule")
After I loaded home page my url looks fine
Example: mysiteurl.com
Then I click Schedule link (if I hover I see the correct url http://mysiteurl.com/home/schedule). If I click it as a result my url will http://mysiteurl.com//#/Home/Schedule. I don't know why its adding # sign to my url but it's causing the issue in my application with other pages.
any idea what I'm doing wrong?
I don't have any custom routing
here is my RegisterRoutes method in Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
Your ActionLinks look fine. I'd guess you have at least one custom route defined inside your RegisterRoutes method. I'd guess you've got a typo somewhere in there.
You could try installing Glimpse via NuGet - it allows you to see exactly which routing rules are firing. Scott Hanselman has this blog on how to use it.