asp.net-mvc-routing

Lower case URLs in ASP.NET MVC

半世苍凉 提交于 2019-12-03 19:07:29
问题 Is it possible to force/extend the routing engine to generate URLs in lower case, giving /controller/action instead of /Controller/Action ? 回答1: What's more, you should force any incoming requests that are uppercase to be redirected to the lowercase version. Search engines treat URLs case-sensitively, meaning that if you have multiple links to the same content, that content's page ranking is distributed and hence diluted. Returning HTTP 301 (Moved Permanently) for such links will cause search

MVC API Routing When Multiple Get Actions Are Present

我与影子孤独终老i 提交于 2019-12-03 17:04:52
There seems to be a thousand people asking the same question on stack overflow, but there doesn't seem to be a single solution to this problem. I am going to ask it again... I have an API controller that has the following actions: // GET api/Exploitation public HttpResponseMessage Get() { var items = _exploitationRepository.FindAll(); var mappedItems = Mapper.Map<IEnumerable<Exploitation>, IEnumerable<ExploitationView>>(items); var response = Request.CreateResponse<IEnumerable<ExploitationView>>(HttpStatusCode.OK, mappedItems); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { }

How to set Area view as home page in ASP.NET MVC?

南笙酒味 提交于 2019-12-03 16:08:30
How to setup route for a view to be as home page of a domain in ASP.NET MVC application which contains Areas. I need a view of a particular area to be home page. How could this be done? I tried using the following code without any success. public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( name: "Home", url: "", defaults: new { controller = "Home", action = "Index" }, namespaces: new string[] { "WebApp.Areas.UI.Controllers" } ); } Brij In the Area folder there is a file by name AreaName AreaRegistration deriving from AreaRegistration, it has a function RegisterArea

Adding Redundant Information to a MVC Route

雨燕双飞 提交于 2019-12-03 16:04:46
As you come to this question you'll notice the title of the question is in the address bar and the link you clicked on to get here. I am not sure the exact terminology so found it difficult to search for but how can I do something similar? That is, How can I add data to the address bar which is purely for show/search engines. Thanks Garry Shutler Taking the example of a Stack Overflow question like this one the URL is: so.com/questions/1142480/adding-redundant-information-to-a-mvc-route However, the functional part of the URL is: so.com/questions/1142480 The way this is achieved is by defining

MVC Routes within WebAPI controller

百般思念 提交于 2019-12-03 15:59:39
Quick question regarding routes within MVC and WebAPI. I have added a route to route config.cs: routes.MapRoute( name: "ConfirmEmail", url: "ConfirmEmail/{userid}", defaults: new { controller = "Email", action = "ConfirmEmail" } ); This is registered in the global.asax as per normal: RouteConfig.RegisterRoutes(RouteTable.Routes); I am trying to generate a URL for use within an email which is sent as part of a function call within a WebAPI controller function. I am using the UrlHelper.Link function to attempt to generate a URL, however I receive an error saying the route cannot be found by name

How do I get rid of Home in ASP.Net MVC?

◇◆丶佛笑我妖孽 提交于 2019-12-03 15:57:39
问题 I know this site is written using ASP.Net MVC and I do not see "/Home" in the url. This proves to me that it can be done. What special route and do I need? 回答1: Just change "Home" to an empty string. routes.MapRoute( "Home", "", new { action = Index, controller = Home } ); 回答2: If you're running on IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in

Difference between Url.RouteUrl() & Url.Action() in MVC3

元气小坏坏 提交于 2019-12-03 14:38:49
问题 I am in the process of generating a URL dynamically in my cshtml page. What is the difference between Url.RouteUrl() & Url.Action()? Which one should I use to generate the URL & what difference do both have in terms of implementation ? Thanks in advance. 回答1: RouteUrl generated the url based on route name. If you have multiple routes with similar parameters the Action method may pick a wrong one - it works based on the order of route definitions. This may take place when your routes have

Built in method to encode ampersands in urls returned from Url.Action?

为君一笑 提交于 2019-12-03 14:03:31
I am using Url.Action to generate a URL with two query parameters on a site that has a doctype of XHTML strict. Url.Action("ActionName", "ControllerName", new { paramA="1" paramB="2" }) generates: /ControllerName/ActionName/?paramA=1&paramB=2 but I need it to generate the url with the ampersand escaped: /ControllerName/ActionName/?paramA=1&paramB=2 The fact that Url.Action is returning the URL with the ampersand not escaped breaks my HTML validation. My current solution is to just manually replace ampersand in the URL returned from Url.Action with an escaped ampersand. Is there a built in or

ASP.NET MVC Route matching for child actions

限于喜欢 提交于 2019-12-03 13:52:26
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? 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 definitions for your child actions as well. Avoid route processing by converting to Html.RenderPartial() If you can

Customizing ASP.NET MVC Routing to service “.json” “.xml” Style Urls

这一生的挚爱 提交于 2019-12-03 12:32:26
问题 I have a search Api I'm working on that needs to return search results in a block of Html (using styles the client has defined on their end). I would also like to return results in Json, for future Api stuff we'll eventually be using. Currently, the routes look like this: /api/1/search/json?param1=blah&param2=blah&etc /api/1/search/html?param1=blah&param2=blah&etc For reference, the pattern here is /{area}/1/{controller}/{action}. I like the look of some Api's I've seen that return results in