asp.net-mvc-routing

Change route collection of MVC6 after startup

岁酱吖の 提交于 2019-11-26 04:21:39
问题 In MVC-5 I could edit the routetable after initial startup by accessing RouteTable.Routes . I wish to do the same in MVC-6 so I can add/delete routes during runtime (usefull for CMS). The code to do it in MVC-5 is: using (RouteTable.Routes.GetWriteLock()) { RouteTable.Routes.Clear(); RouteTable.Routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\"); RouteTable.Routes.MapRoute( name: \"Default\", url: \"{controller}/{action}/{id}\", defaults: new { controller = \"Home\", action = \"Index\", id =

ASP.NET MVC ambiguous action methods

你。 提交于 2019-11-26 03:47:24
问题 I have two action methods that are conflicting. Basically, I want to be able to get to the same view using two different routes, either by an item\'s ID or by the item\'s name and its parent\'s (items can have the same name across different parents). A search term can be used to filter the list. For example... Items/{action}/ParentName/ItemName Items/{action}/1234-4321-1234-4321 Here are my action methods (there are also Remove action methods)... // Method #1 public ActionResult Assign(string

Routing for custom ASP.NET MVC 404 Error page

强颜欢笑 提交于 2019-11-26 03:36:53
问题 I am trying to make a custom HTTP 404 error page when someone types in a URL that doesn\'t invoke a valid action or controller in ASP.NET MVC, instead of it displaying the generic \"Resource Not Found\" ASP.NET error. I don\'t want to use the web.config to handle this. Is there any kind of routing magic I can do to catch any invalid URLs? Update: I tried the answer given, however I still get the ugly \"Resource Not Found\" message. Another update: Ok, apparently something changed in RC1. I\

Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287

孤街醉人 提交于 2019-11-26 03:24:34
问题 The URL I\'m trying to let work is one in the style of: http://somedomain.com/api/people/staff.33311 (just like sites as LAST.FM allow all sort of signs in their RESTFul & WebPage urls, for example \"http://www.last.fm/artist/psy\'aviah\" is a valid url for LAST.FM). What works are following scenarios: - http://somedomain.com/api/people/ - which returns all people - http://somedomain.com/api/people/staff33311 - would work as well, but it\'s not what I\'m after I\'d want the url to accept a \

How do you request static .html files under the ~/Views folder in ASP.NET MVC?

泄露秘密 提交于 2019-11-26 02:19:37
问题 I want to be able to request static .html files which are located in the ~/Views folder. According to the documentation, the routing system checks to see if a URL matches a disk file before evaluating the application\'s routes. But when I request the file a 404 error arises. My file is located in ~/Views folder. The URL is: http://[localhost]/Views/HtmlPage1.html What have I missed? 回答1: I want to be able to request static .html files which are located in the '~/Views' folder. You can't.

URL-encoded slash in URL

早过忘川 提交于 2019-11-26 01:49:28
问题 My Map is: routes.MapRoute( \"Default\", // Route name \"{controller}/{action}/{id}\", // URL with params new { controller = \"Home\", action = \"Index\", id = \"\" } // Param defaults ); If I use the URL http://localhost:5000/Home/About/100%2f200 there is no matching route. I change the URL to http://localhost:5000/Home/About/100 then the route is matched again. Is there any easy way to work with parameters that contain slashes? Other escaped values (space %20 ) seem to work. EDIT: To encode

URL-encoded slash in URL

大兔子大兔子 提交于 2019-11-26 01:26:57
My Map is: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with params new { controller = "Home", action = "Index", id = "" } // Param defaults ); If I use the URL http://localhost:5000/Home/About/100%2f200 there is no matching route. I change the URL to http://localhost:5000/Home/About/100 then the route is matched again. Is there any easy way to work with parameters that contain slashes? Other escaped values (space %20 ) seem to work. EDIT: To encode Base64 works for me. It makes the URL ugly, but that's OK for now. public class UrlEncoder { public string

Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287

故事扮演 提交于 2019-11-26 01:08:16
The URL I'm trying to let work is one in the style of: http://somedomain.com/api/people/staff.33311 (just like sites as LAST.FM allow all sort of signs in their RESTFul & WebPage urls, for example " http://www.last.fm/artist/psy'aviah " is a valid url for LAST.FM). What works are following scenarios: - http://somedomain.com/api/people/ - which returns all people - http://somedomain.com/api/people/staff33311 - would work as well, but it's not what I'm after I'd want the url to accept a "dot", like the example below - http://somedomain.com/api/people/staff.33311 - but this gives me a HTTP Error

Why map special routes first before common routes in asp.net mvc?

荒凉一梦 提交于 2019-11-25 23:59:22
问题 From the www: ...The routing engine will take the first route that matches the supplied URL and attempt to use the route values in that route. Therefore, less common or more specialized routes should be added to the table first, while more general routes should be added later on... Why should I map specialized routes first? Someone can give me an example please where I can see the failing of \"map common route first\" ? 回答1: The routing engine will take the first route that matches the

Is it possible to make an ASP.NET MVC route based on a subdomain?

允我心安 提交于 2019-11-25 22:20:31
问题 Is it possible to have an ASP.NET MVC route that uses subdomain information to determine its route? For example: user1 .domain.com goes to one place user2 .domain.com goes to another? Or, can I make it so both of these go to the same controller/action with a username parameter? 回答1: You can do it by creating a new route and adding it to the routes collection in RegisterRoutes in your global.asax. Below is a very simple example of a custom Route: public class ExampleRoute : RouteBase { public