asp.net-mvc-routing

What is routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”)

…衆ロ難τιáo~ 提交于 2019-11-26 09:24:00
问题 What is routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\") I cannot find any .axd file in my project, can I remove this route rule? 回答1: .axd files don't exist physically. ASP.NET uses URLs with .axd extensions (ScriptResource.axd and WebResource.axd) internally, and they are handled by an HttpHandler. Therefore, you should keep this rule, to prevent ASP.NET MVC from trying to handle the request instead of letting the dedicated HttpHandler do it. 回答2: Some Background If you open up this file:

How do I route a URL with a querystring in ASP.NET MVC?

烈酒焚心 提交于 2019-11-26 08:34:57
问题 I\'m trying to setup a custom route in MVC to take a URL from another system in the following format: ../ABC/ABC01?Key=123&Group=456 The 01 after the second ABC is a step number this will change and the Key and Group parameters will change. I need to route this to one action in a controller with the step number key and group as paramters. I\'ve attempted the following code however it throws an exception: Code: routes.MapRoute( \"OpenCase\", \"ABC/ABC{stepNo}?Key={key}&Group={group}\", new

How to get RouteData by URL?

二次信任 提交于 2019-11-26 08:21:20
问题 I need to get RoutData by given URL string in ASP.NET MVC application. I\'ve found the way that I need to mock HttpContextBase based on my URL string and then pass it to RouteTable.Routes.GetRouteData() method in Route Parsing (Uri to Route) thread. How to mock HttpContextBase to retrieve RouteData by URL string using RouteTable.Routes.GetRouteData() ? Or is there another way to retrieve RouteData by URL? 回答1: I used Moq to determine what members of HttpContextBase are used in GetRouteData()

How can I create a friendly URL in ASP.NET MVC?

允我心安 提交于 2019-11-26 07:58:36
问题 How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we\'ve got a URL that looks like this: http://site/catalogue/BrowseByStyleLevel/1 The 1 is Id of the study level (Higher in this case) to browse, but I\'l like to reformat the URL in the same way StackOverflow does it. For example, these two URLs will take you to the same place: https://stackoverflow.com/questions/119323/nested-for-loops-in-different-languages https://stackoverflow.com/questions/119323/ EDIT: The

ASP.Net MVC route to catch all *.aspx requests

落爺英雄遲暮 提交于 2019-11-26 07:47:49
问题 This must have been asked before, but after reading here, here, here and here I can\'t extrapolate the relevant parts to make it work. I am revamping an old web forms site into MVC, and want to catch particular incoming HTTP requests so that I can issue a RedirectPermanent (to protect our Google rankings and avoid users leaving due to 404\'s). Rather than intercept all incoming requests, or parse for some id value, I need to intercept all requests that end in (or contain) the .aspx file

ApiController returns 404 when ID contains period

送分小仙女□ 提交于 2019-11-26 07:39:53
问题 I have an ApiController and I want to use email addresses as the ID parameter for requests: // GET api/employees/email@address.com public CompactEmployee Get(string id) { var email = id; return GetEmployeeByEmail(email); } However, I cannot get this to work (returns 404 ): http://localhost:1080/api/employees/employee@company.com The following all work: http://localhost:1080/api/employees/employee@company http://localhost:1080/api/employees/employee@company. http://localhost:1080/api/employees

Infinite URL Parameters for ASP.NET MVC Route

人走茶凉 提交于 2019-11-26 07:33:06
问题 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

MVC Routing Parameter Precedence

隐身守侯 提交于 2019-11-26 06:48:56
问题 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\"

ASP.NET MVC custom routing for search

若如初见. 提交于 2019-11-26 06:14:20
问题 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

ASP.Net MVC Handling Segments with Route

感情迁移 提交于 2019-11-26 04:28:35
问题 I am new to ASP.Net MVC and facing a problem. Here it is. routes.MapRoute( \"SearchResults\",// Route name \"{controller}/{action}/{category}/{manufacturer}/{attribute}\", new { controller = \"Home\", action = \"CategoryProducts\", category = UrlParameter.Optional, manufacturer = UrlParameter.Optional, attribute = UrlParameter.Optional } ); And here is my controller method. public ActionResult CategoryProducts(string category, string manufacturer, string attribute) { string[]