asp.net-mvc-routing

asp.net mvc does not receive the GET request with a period in it

隐身守侯 提交于 2019-12-22 04:36:19
问题 I'm using .net4.5rc with MVC4.0rc The code below is taken from a MVC webapi application but I the same behaviour is there for reular asp.net mvc My registerroutes code looks like this routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "R1", routeTemplate: "product/{id}", defaults: new { controller="Product", id = RouteParameter.Optional } ); This works well with Ids that doesn't have a period in them. However when I ask for a product with a period in it, the call

Language-specific Default URL using MVC's Attribute Routing and RouteLocalization.mvc

耗尽温柔 提交于 2019-12-21 17:44:18
问题 I would like to be able to create a succinct language-specific default URL for my website so that when someone browses to: somesite.com They get redirected to a language-culture page such as: somesite.com/en-US/ somesite.com/sp-MX/ somesite.com/fr-FR/ Specifically, I do not want /Home/Index appended to the URLs: somesite.com/en-US/Home/Index somesite.com/sp-MX/Home/Index somesite.com/fr-FR/Home/Index I am committed to making this site using RouteLocalization.mvc Dresel/RouteLocalization

Routing legacy requests with and without querystring

本秂侑毒 提交于 2019-12-21 16:25:39
问题 (Before starting: I am aware of this and this. I'd like to find a more concise solution -if possible- for a slightly more specific problem) I'm rewriting an old Webforms app in MVC. As usual, no permalinks should be broken. I'm using standard {controller}/{action}/{id} routes. Legacy paths are usually SomePage.aspx?ID=xxx , and I have one particular case where Foo.aspx is a list of Bar (new URL: /Bar or /Bar/Index ) and Foo.aspx?ID=xxx is the Bar detail (new URL: /Bar/View/xxx ) One possible

Routing legacy requests with and without querystring

大憨熊 提交于 2019-12-21 16:23:12
问题 (Before starting: I am aware of this and this. I'd like to find a more concise solution -if possible- for a slightly more specific problem) I'm rewriting an old Webforms app in MVC. As usual, no permalinks should be broken. I'm using standard {controller}/{action}/{id} routes. Legacy paths are usually SomePage.aspx?ID=xxx , and I have one particular case where Foo.aspx is a list of Bar (new URL: /Bar or /Bar/Index ) and Foo.aspx?ID=xxx is the Bar detail (new URL: /Bar/View/xxx ) One possible

Create a MVC route ending “.js” and returning JavaScript?

对着背影说爱祢 提交于 2019-12-21 12:32:54
问题 I'd like to auto-generate some JavaScript files, with proper .js extensions in their URLs, using ASP.NET MVC 5. Here's my problem; I'm using require.js throughout my site and it's working pretty well. However, not all of my JavaScript files are real files on disk. Some of them must be generated at runtime. So I've written a controller which generates the dynamic JavaScript files, and serves them when using the default routing; // ~/Resource/CommonRes -- from ResourceController.CommonRes()

Valid routes not discovered by MVC.ApiExplorer

拈花ヽ惹草 提交于 2019-12-21 09:06:08
问题 When using ASP.NET Web API Help Page and the related MVC.ApiExplorer I have valid routes that are accessible via http yet aren't discovered by ApiExplorer. These routes are only found when a general routing rule is used. Usage of a more specific rule (in conjunction with the general one) seems to hide routes from the ApiExplorer. In an example case of three rules two routes relate to a GET and a POST action on a controller method which take no query parameters go MIA. public class

ASP.NET MVC routing by string id?

孤街醉人 提交于 2019-12-21 07:23:12
问题 In ASP.NET 2, how do I create a route that allows lookup of an object (eg Product) by a string id (eg ProductCode)? The route for looking up the same object by it's integer id (eg ProductId) is automatic, so I don't actually know how it works. The automatic route by id is: /Product/1 How do I also create a 2nd route that uses a string id? /Product/red-widget And how do I do it so that both routes are available? 回答1: You should take a look at using a route constraint to do this. See http://www

Multilingual URLs with ASP.NET MVC

一世执手 提交于 2019-12-21 05:19:06
问题 I’m working out the concepts for a new project where I need to support for multilingual URL’s. Ideally all URL’s need to be in the native language of the user. So we don’t want to use domain.com/en/contact and domain.com/es/contact but we like domain.com/contact and domain.com/contactar (contactar is Spanish for contact). Internally both should be routed to the same ContactController class. This could be handled by adding multiple static routes to Global.asax.cs for each language but we’d

ASP.NET MVC Route matching for child actions

喜夏-厌秋 提交于 2019-12-21 04:23:13
问题 Does the approach of route matching for child actions differ from usual actions? In other words, do child actions have some autogenerated url to make matching similar to what is done for parent actions? 回答1: No difference between parent or child action processing Any action follows the same route definition you've set in your Application_Start . That means parent actions as well as child ones. If you gave specific routes for all actions in your application, then you must provide route

ASP.NET MVC Default routes accessible via area routes

为君一笑 提交于 2019-12-20 12:38:29
问题 So far (for brevity) I have one route in global.asax registered like this: routes.Add(new LowercaseRoute("{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional }), DataTokens = rootNamespace }); Where "rootNamespace" is var rootNamespace = new RouteValueDictionary(new { namespaces = new[] { "MyApp.Web.Controllers" } }); LowercaseRoute inherits from Route and just makes all paths lowercase. I also