asp.net-mvc-routing

How to make IRouteConstraint filter route

筅森魡賤 提交于 2019-12-18 02:18:05
问题 I wrote a custom route constraint, but its filter just doesn't get recognized. Does anyone have an example working use of IRouteConstraint ? Also, note to developers: I get double display of the form on my android. Something must be wrong with the partial rendering? 回答1: Here's a simple constraint that looks up an article slug in a fictional repository: public class SlugRouteConstraint : IRouteConstraint { private readonly ISlugRepository slugRepository = new SlugRepository(); public bool

How to route GET and DELETE requests for the same url to different controller methods

*爱你&永不变心* 提交于 2019-12-18 01:52:16
问题 Here are my routes in Global.asax routes.MapRoute("PizzaGet", "pizza/{pizzaKey}", new { controller = "Pizza", action = "GetPizzaById" }); routes.MapRoute("DeletePizza", "pizza/{pizzaKey}", new { controller = "Pizza", action = "DeletePizza" }); Here are the my controller methods [AcceptVerbs(HttpVerbs.Get)] public ActionResult GetPizzaById(long pizzaKey) [AcceptVerbs(HttpVerbs.Delete)] public ActionResult DeletePizza(long pizzaKey) When I do a GET it returns the object, but when I do a DELETE

ASP.net MVC custom route handler/constraint

ⅰ亾dé卋堺 提交于 2019-12-17 23:33:39
问题 I need to implement an MVC site with urls per below: category1/product/1/wiki category1/product/2/wiki category1/sub-category2/product/3/wiki category1/sub-category2/sub-category3/product/4/wiki etc. etc. where the matching criteria is that the url ends with "wiki". Unfortunately the below catch-all works only in the last part of the url: routes.MapRoute("page1", // Route name "{*path}/wiki", // URL with parameters new { controller = "Wiki", action = "page", version = "" } // Parameter

Routing Reserved Words in ASP.Net

南笙酒味 提交于 2019-12-17 20:56:06
问题 I have a legacy url that I wish to map to a route in my ASP.Net MVC application e.g. http://my.domain.com/article/?action=detail&item=22 Now in route creation action has a special meaning so my to create this route? The controller is a RedirectController and the action is Item. routes.MapRoute( name: "Redirect", url: "article", defaults:new { controller = "redirect", action = "item"} ); So my problem is that action in the query string gets overwritten by the action in the defaults . Is there

How to access the current HttpRequestMessage object globally?

我们两清 提交于 2019-12-17 18:45:26
问题 I have a method which creates an HttpResponseMessage containing an Error object which will be returned based on the current request media type formatter. Currently, I have hardcoded the XmlMediaTypeFormatter but I'd like to be able to find the current request MediaTypeFormatter at runtime but I don't have access to the current request object since my below code exists on a separate class library. private HttpResponseMessage Create(HttpStatusCode statusCode, string errorCode, string

Differentiate Guid and string Parameters in MVC 3

佐手、 提交于 2019-12-17 18:33:40
问题 Using the out-of-the-box method locators in ASP.NET MVC (3 or 4DP), is there a way to have the MVC framework differentiate between a string and Guid without needing to parse the parameter in the controller action? Usage examples would be for the URL http://[domain]/customer/details/F325A917-04F4-4562-B104-AF193C41FA78 to execute the public ActionResult Details(Guid guid) method, and http://[domain]/customer/details/bill-gates to execute the public ActionResult Details(string id) method. With

asp.net mvc multilanguage urls/routing

有些话、适合烂在心里 提交于 2019-12-17 15:29:08
问题 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

How am I supposed to use ReturnUrl = ViewBag.ReturnUrl in MVC 4

ε祈祈猫儿з 提交于 2019-12-17 15:27:34
问题 I'm working on 'ASP.NET MVC 4' application. I'm using/learning SimpleMembershipProvider and try to stick to the default logic created by VS2012 with the Internet template (if I'm not mistaken, the one with 'SimpleMembershipProvider' out of the box). I'm stuck at the AccountController where I just can't figure put how exactly I can use this method: private ActionResult RedirectToLocal(string returnUrl) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return

MVC 2 AreaRegistration Routes Order

社会主义新天地 提交于 2019-12-17 10:56:07
问题 I noticed that in MVC 2 Preview 2, AreaRegistration is loading the routes for each area in an arbitrary order. Is there a good way to get one before the other? For example, I have two areas - "Site" and "Admin". Both have a "Blog" controller. I would like the following: /admin/ --> go to Admin's Blog controller / --> go to Site's Blog controller. The problem is that it is loading the site's route first, so it is matching {controller}/{action}/{id} instead of admin/{controller}/{action}/{id}

How to achieve a dynamic controller and action method in ASP.NET MVC?

青春壹個敷衍的年華 提交于 2019-12-17 08:49:11
问题 In Asp.net MVC the url structure goes like http://example.com/{controller}/{action}/{id} For each "controller", say http://example.com/blog, there is a BlogController. But my {controller} portion of the url is not decided pre-hand, but it is dynamically determined at run time, how do I create a "dynamic controller" that maps anything to the same controller which then based on the value and determines what to do? Same thing with {action}, if the {action} portion of my url is also dynamic, is