asp.net-mvc-routing

MVC3 RESTful API Routing & Http Verb Handling

非 Y 不嫁゛ 提交于 2020-01-01 08:54:05
问题 I want to build a RESTful Json Api for my MVC3 application. I need help with handling multiple Http Verbs for the manipulation of a single object instance. What I've read/studied/tried MVC attributes ( HttpGet , HttpPost , etc.) allow me to have a controller with multiple actions sharing the same name, but they still must have different method signatures. Route constraints happen in the routing module before MVC kicks in and would result in me having 4 explicit routes, and still require

Setting up Index as the default route for a controller

拜拜、爱过 提交于 2020-01-01 05:13:27
问题 I have a url http://www.roadkillwiki.org/Page/Index/documentation which I want to turn into http://www.roadkillwiki.org/Page/documentation That could also be something like http://www.roadkillwiki.org/Page/my-url-with-spaces - the parameter is a string. The route setup I've tried is: routes.MapRoute( "ControllerDefault", "{controller}/{id}", new { controller = "Page", action = "Index", id = UrlParameter.Optional } ); However this is interfering with the default "id" route that MVC projects

Remove or replace existing routes in RouteTable

帅比萌擦擦* 提交于 2020-01-01 04:34:08
问题 I got a ASP.NET MVC 2.0 Preview 1 app and started to create some areas which contains their own routes. I want to have a way to overwrite these routes in the main project. I can of course not add a new route with the same name. I can see the RouteTable.Routes.Remove(RouteBase item) but not sure how to use it. //Need to remove "PostIndex" before adding it again routes.MapAreaRoute( "OurAreaNameSpace", "PostIndex", "post/index/{currentPage}", new { controller = "Post", action = "Index",

How to make more MapHttpRoutes for MVC 4 Api

☆樱花仙子☆ 提交于 2019-12-31 12:53:39
问题 I have 2 API routes for my API atm, but I want to add more, and the way I am doing it it seems to overwrite each other, so in the code I pasted, only the CreateUser route works. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "CreateUser", routeTemplate: "api/{controller}/{cUser}", defaults: new { controller = "User", action = "CreateUser", cUser = RouteParameter.Optional }); routes.MapHttpRoute( name:

How could I route to the /Home/Index action regardless of the URL?

╄→尐↘猪︶ㄣ 提交于 2019-12-31 06:58:07
问题 I am looking for a way to route all traffic to my Home controller and to the Index action, regardless of the URL they use to arrive at my site. As long as they are using www.MyDomain.com, a user visiting www.MyDomain.com/Controller1/Action1 would need to all be routed to the same action as a user visiting www.MyDomain.com/Controller2/Action3/ID6 I can redirect each one of these manually but some of the URL's may be dynamically generated and therefore I need to learn how to catch all and

How to generate a path/url from a Route in the Routes table?

江枫思渺然 提交于 2019-12-31 05:25:18
问题 I have an ASP.NET MVC web application, and I've registered a number of routes in my Global.asax. I would like to know how I can programmatically build (generate a string url) any one of those registered routes from within my Controller. I did the same thing in Web Forms with .NET 4.0 using Page.GetRouteUrl(routeName, routeParams) but can't figure out how to do the same thing in MVC (I'm an MVC newbie). 回答1: You could use the UrlHelper class inside your controller action. public ActionResult

How do I generically implement URL-rewriting in a MapRoute method?

一世执手 提交于 2019-12-31 03:22:06
问题 I am attempting to rewrite URL's from C#'s Pascal-case to SEO-friendly format. For example, I want something like /User/Home/MyJumbledPageName to look like this: /user/home/my-jumbled-page-name // lower-case, and words separated by dashes Here is my method for converting each "token" in the URL: public static string GetSEOFriendlyToken(string token) { StringBuilder str = new StringBuilder(); for (int i = 0, len = token.Length; i < len; i++) { if (i == 0) { // setting the first capital char to

ASP.NET MVC Custom Routing Long Custom Route not Clicking in my Head

不羁的心 提交于 2019-12-31 02:10:15
问题 I have spent several hours today reading up on doing Custom Routing in ASP.NET MVC. I can understand how to do any type of custom route if it expands from or is similar/smaller than the Default Route. However, I am trying figure out how to do a route similar to: /Language/{LanguageID}/Question/{QuestionID}/ And what I would like, too, is similar to how SO works. Something like: /Language/{LanguageID}/Arabic/Question/{QuestionID}/Some-Question-Title Where "Arabic" and "Some-Question-Title" can

How to add route to dynamic robots.txt in ASP.NET MVC?

最后都变了- 提交于 2019-12-30 08:52:52
问题 I have a robots.txt that is not static but generated dynamically. My problem is creating a route from root/robots.txt to my controller action. This works : routes.MapRoute( name: "Robots", url: "robots", defaults: new { controller = "Home", action = "Robots" }); This doesn't work : routes.MapRoute( name: "Robots", url: "robots.txt", /* this is the only thing I've changed */ defaults: new { controller = "Home", action = "Robots" }); The ".txt" causes ASP to barf apparently 回答1: You need to add

Routing to controller with a required, non-empty Guid parameter

我怕爱的太早我们不能终老 提交于 2019-12-30 08:26:12
问题 I would like to map http://localhost/Guid-goes-here to ResellerController and fire Index action of that controller only when Guid-goes-here is not the empty Guid. My routing table looks like this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Reseller", "{id}", new { controller = "Reseller", action = "Index", id = Guid.Empty } // We can mark parameters as UrlParameter.Optional, but how to make it required? );