asp.net-mvc-routing

How to have folder and controller with same name in ASP.NET MVC?

回眸只為那壹抹淺笑 提交于 2019-11-27 23:40:59
问题 I have a MVC controller called Downloads. http://mysite/Downloads I also want to put a physical file in a physical folder called http://mysite/Downloads/MyFile.zip. If I simply create a folder, I get a 403 when browsing to http://mysite/Downloads. (Most likely because of directory browsing is disabled) But I want the MVC controller to kick in instead. How do I do that? 回答1: If you browse to http://mysite/Downloads/{ACTION} it will fire your controllers action. The only thing that won't work

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

自古美人都是妖i 提交于 2019-11-27 21:15:46
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 problem is with the RouteAsync method. public Task RouteAsync(RouteContext context) { var requestPath =

How to determine if an arbitrary URL matches a defined route

浪尽此生 提交于 2019-11-27 20:40:51
How can I tell if a string matches a particular named route? I have a route like this: routes.MapRoute( "FindYourNewRental", "find-your-new-rental/{market}/{community}.html", new { controller = "FindYourNewRental", action = "Community" } ); string url = "http://www.website.com/find-your-new-rental/northerncalifornia/sacramento.html" How can I programmatically tell if the 'url' string matches that route? Something like this: // matches url with the named route "FindYourNewRental" if (IsRouteMatch(url, "FindYourNewRental")) { // do something } public bool IsRouteMatch(string url, string

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

删除回忆录丶 提交于 2019-11-27 20:37:14
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 seem to resolve (consistent 404's on /foo, /foo/bar and /foo/bar.txt). A similar pattern using a slash

asp.net mvc multilanguage urls/routing

痞子三分冷 提交于 2019-11-27 18:12:17
This is a two part question regarding asp.net mvc multilanguage urls/routing and SEO best practices/benefits… Question Part 1) I’m being asked to create a new ASP.NET MVC website that will support a minimum (at first) of two languages (English and French) perhaps in the future, 3 languages… As far as localizing the application (labels, jQuery errors, etc) things should be ok using resource files and I’ve found many examples on this…but my concern/question is more about the URLs. In terms of SEO, what is the recommended approach between these two fashions? Fashion 1 (no culture folder) www

url with extension not getting handled by routing

≡放荡痞女 提交于 2019-11-27 17:38:42
问题 I've been folowing the advice from this article for setting up a robots.txt file in asp.net mvc3 for using a controller to handle the server response, and IIS 8.0 express is returning a file not found error, rather than an asp.net error. How do I get IIS to not look for a file in these cases? Is there something I need in the web.config? 回答1: IIS tries to be intelligent here. He intercepts the dot in the url and thinks that this is a static file and attempts to serve it with the default

Routing in Asp.net Mvc 4 and Web Api

依然范特西╮ 提交于 2019-11-27 17:27:14
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/FruitApi/GetSeasonalFruit Fruit GetFruits(string id) = api/FruitApi/15 Fruit GetFruitsByName(string name)

asp.NET: Unknown length MVC paths

随声附和 提交于 2019-11-27 17:14:19
问题 I am building a MVC application in asp.NET for a web portal. I have prepared a series of controllers, and mapped all the paths that don't macth to this to a Page controller, which will render the appropriate page. My default route works like this: routes.MapRoute( "Default", "{level1}/{level2}/{level3}", new { controller = "Page", action = "Index", level1 = "home", level2 = "", level3 = "" } ); But this has fixed width, it will accept only up to 3 levels. Moreover, I'd like to manage actions

WebAPI route 404's when there is a trailing space in the URL

萝らか妹 提交于 2019-11-27 15:08:59
With the default web api route config.Routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); and a controller public class TestController : ApiController { [HttpGet] public HttpResponseMessage Get(string id) { return Request.CreateResponse(HttpStatusCode.OK, id); } } A request to 'api/test/1' returns 1 If for some reason you send a request to 'api/test/1%20' the route 404's. Now this example may seem silly since browsers trim trailing spaces, but for a route like 'api/{controller}/{id}/{extrastuff}' the space in '1 '

Trailing slash on an ASP.NET MVC route

大憨熊 提交于 2019-11-27 14:55:18
问题 In the latest MVC preview, I'm using this route for a legacy URL: routes.MapRoute( "Legacy-Firefox", // Route name "Firefox-Extension/", // URL with parameters new { controller = "Home", action = "Firefox", id = "" } // Parameter defaults ); The problem is that both of these URL's work: http://example.com/Firefox-Extension http://example.com/Firefox-Extension/ I only want the second to work (for SEO). Also, when I create a link to that page, the routing engine gives me back a URL without a