asp.net-mvc-routing

Imlementing a Custom IRouter in ASP.NET 5 (vNext) MVC 6

大憨熊 提交于 2019-11-26 20:36:11
问题 I am attempting to convert this sample RouteBase implementation to work with MVC 6. I have worked out most of it by following the example in the Routing project, but I am getting tripped up on how to return the asynchronous Task from the method. I really don't care if it actually is asynchronous (cheers to anyone who can provide that answer), for now I just want to get it functioning. I have the outgoing routes functioning (meaning ActionLink works fine when I put in the route values). The

Can periods be used in Asp.Net Web Api Routes?

送分小仙女□ 提交于 2019-11-26 20:24:34
问题 I'm working on moving an API project from raw http handlers where I'm using periods in the paths: http://server/collection/id.format I would like to follow the same URL schema in a Web Api (self-hosted) version, and tried this: var c = new HttpSelfHostConfiguration(b); c.Routes.MapHttpRoute( name: "DefaultApiRoute", routeTemplate: "{controller}/{id}.{format}", defaults: new { id = RouteParameter.Optional, format = RouteParameter.Optional }, constraints: null ); Unfortunately, that doesn't

Infinite URL Parameters for ASP.NET MVC Route

≡放荡痞女 提交于 2019-11-26 20:05:26
I need an implementation where I can get infinite parameters on my ASP.NET Controller. It will be better if I give you an example : Let's assume that I will have following urls : example.com/tag/poo/bar/poobar example.com/tag/poo/bar/poobar/poo2/poo4 example.com/tag/poo/bar/poobar/poo89 As you can see, it will get infinite number of tags after example.com/tag/ and slash will be a delimiter here. On the controller I would like to do this : foreach(string item in paramaters) { //this is one of the url paramaters string poo = item; } Is there any known way to achieve this? How can I get reach the

MVC Routing Parameter Precedence

守給你的承諾、 提交于 2019-11-26 19:12:32
I came across a scenario where I had the default MVC Route setup. Like So. routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); Then navigating to a url as such domain/controller/action/1234 On this page I was then navigating to the same page but with different parameters after a certain event. Like so. var id = $(this).data("id"); var url = "@Url.Action("action", "controller", new { area = ""})"; var params = $.param({id: id, vrnsearch: true}); var fullUrl = url += "?" + params; window

Routing in Asp.net Mvc 4 and Web Api

為{幸葍}努か 提交于 2019-11-26 18:59:16
问题 Can I use the following two route rule together ? config.Routes.MapHttpRoute( name: "ActionApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); Say by controller is = FruitApiController:ApiController and I wish to have the following List<Fruit> Get() = api/FruitApi/ List<Fruit> GetSeasonalFruits() = api

How does a method in MVC WebApi map to an http verb?

旧时模样 提交于 2019-11-26 18:39:28
In the 5-minute video at the following link, at the 1:10 mark, Jon Galloway says that adding a method called DeleteComment to his CommentsController controller class will by convention map automatically to the delete http verb. How does MVC with WebApi know how to rout the methods to the right verbs? I know the routing in the global.asax.cs file routes requests to the correct controller, but how does a delete request get "mapped by convention" to the delete method, or any method? Especially when there can be more than 1 method for each verb? "By convention" makes me think it's just looking at

Asp.Net Routing - Display complete URL

妖精的绣舞 提交于 2019-11-26 18:34:28
问题 I have a domain "http://www.abc.com". I have deployed an ASP.net MVC4 app on this domain. I have also configured a default route in RouteConfig.cs as shown below routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "MyApp", action = "Home", id = UrlParameter.Optional } ); The above mapping ensures that anyone attempting to visit "http://www.abc.com" is automatically shown the page for "http://www.abc.com/MyApp/Home" Everything works as expected but

ASP.Net MVC routing legacy URLs passing querystring Ids to controller actions

我只是一个虾纸丫 提交于 2019-11-26 18:25:13
问题 We're currently running on IIS6, but hoping to move to IIS 7 soon. We're moving an existing web forms site over to ASP.Net MVC. We have quite a few legacy pages which we need to redirect to the new controllers. I came across this article which looked interesting: http://blog.eworldui.net/post/2008/04/ASPNET-MVC---Legacy-Url-Routing.aspx So I guess I could either write my own route handler, or do my redirect in the controller. The latter smells slightly. However, I'm not quite sure how to

ASP.NET MVC custom routing for search

时光总嘲笑我的痴心妄想 提交于 2019-11-26 18:15:52
Here is my scenario. For the example lets say that I need to return a list of cars based on a search criteria. I would like to have a single View to display the results since the output will be the same, but I need several ways of getting there. For instance, I may have a Form with a textbox to search by year. I may have another separate page that contains a hyperlink for all red, Toyota cars. How do I handle these multiple scenarios in the same View and Controller. My dilemma is that the search could contain several options… year, make, model, etc but I don’t know where to put them. What is

Attribute Routing not working in areas

孤街醉人 提交于 2019-11-26 18:01:14
问题 Scenario: I have a Forms area in my ASP.NET MVC 5 site. I'm trying to redirect to the Details Action which uses a custom route defined using the new Attribute Routing feature. The RedirectToAction: return RedirectToAction("Details", new { slug }); The action I'm redirecting to: [HttpGet] [Route("forms/{slug}")] public ActionResult Details(string slug) { var form = FormRepository.Get(slug); ... return View(model); } I would expect a redirect to http://localhost/forms/my-slug but instead the