asp.net-mvc-routing

Get a complete url like http://google.com as action input

情到浓时终转凉″ 提交于 2019-12-01 21:44:28
I want to get url in my action to return the page's PageRank. I have a route like this: routes.MapRoute( name: "PRURL", url: "Utility/PR/{*url}", defaults: new { controller = "Utility", action = "PR", url = UrlParameter.Optional } ); but whenever I go to http://localhost:1619/Utility/PR/http://google.com I just get a System.Web.HttpException that tell me A potentially dangerous Request.Path value was detected from the client (:). I want to resolve this problem but I don't know how! can anybody help me? Update I tried [ValidateInput(false)] but it doesn't resolved the problem! the action is

Wildcards with ASP.NET MVC MapPageRoute to support organizing legacy code

元气小坏坏 提交于 2019-12-01 21:21:28
问题 I'm working on migrating an existing ASP.NET web site into an MVC project. There are several (60+) pages that I don't want to rewrite just yet, and so I'm wondering if there's a way that I can: Move the existing .aspx pages (both markup and code-behind files) into a 'Legacy' folder in my MVC structure Set up routing so a call to /foo.aspx (without 'legacy') will actually invoke ~/Legacy/foo.aspx Effectively, I don't want "legacy" in the URL, but I also don't want the MVC solution to be full

Attribute Routing with Multiple Leading Zero Decimals

只愿长相守 提交于 2019-12-01 21:16:50
Current ActionResult: [Route("EvaluatorSetup/{evalYear}/{department}")] public ActionResult RoutedEvaluatorSetup(int evalYear, string department) { return EvaluatorSetup((int?)evalYear, department); } I would like to use the url: /EvaluatorSetup/2014/001.3244 where the {department} is a ultimately a string, however, the routing is not picking up {department} as a string. A. I don't know what type MVC is expecting for "001.3244", or what it is picking it up as. B. I want to maintain it as a string with optional leading zeros, as in the example. What am I doing wrong? Update: What I mean is,

Multiple actions were found that match the request [duplicate]

我的梦境 提交于 2019-12-01 21:07:47
This question already has an answer here: Multiple actions were found that match the request in Web Api 18 answers I have read a lot of questions about routing and controllers, but I simply can't find what I'm looking for. I have this controller which has this structure: Update: Included full class source. public class LocationsController : ApiController { private readonly IUnitOfWork _unitOfWork; public LocationsController(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } // GET /api/locations/id public Location Get(Guid id) { return this.QueryById<Location>(id, _unitOfWork); } // GET

How to make MVC Routing handle url with dashes

走远了吗. 提交于 2019-12-01 20:54:10
I have a route defined as follows in MVC: routes.MapRoute( name: "ContentNavigation", url: "{viewType}/{category}-{subCategory}", defaults: new { controller = "Home", action = "GetMenuAndContent", viewType = String.Empty, category = String.Empty, subCategory = String.Empty }); If I navigate to http://example.com/something/category-and-this-is-a-subcategory It fills the variables as: viewType: "something" category: "category-and-this-is-a" subCategory: "subcategory". What I want is for the word before the first dash to always go into category , and the remaining into subcategory . So it would

RouteCollection' doesn't contain a definition for 'MapMvcAttributeRoutes

删除回忆录丶 提交于 2019-12-01 20:14:16
I just had to downgrade my ASP.Net 4.5.2 application to ASP.Net 4.0. Of course this brings problems with it, like references that are not installed correct. I solved some of them already, but I can't get my head around an error: CS106 'RouteCollection' does not contain a definition for 'MapMvcAttributeRoutes' and no extension method 'MapMvcAttributeRoutes' accepting a first argument of type 'RouteCollection' could be found public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes();

Wildcards with ASP.NET MVC MapPageRoute to support organizing legacy code

被刻印的时光 ゝ 提交于 2019-12-01 19:59:18
I'm working on migrating an existing ASP.NET web site into an MVC project. There are several (60+) pages that I don't want to rewrite just yet, and so I'm wondering if there's a way that I can: Move the existing .aspx pages (both markup and code-behind files) into a 'Legacy' folder in my MVC structure Set up routing so a call to /foo.aspx (without 'legacy') will actually invoke ~/Legacy/foo.aspx Effectively, I don't want "legacy" in the URL, but I also don't want the MVC solution to be full of legacy .aspx pages. I accept that this is a very minor point, I'm just curious if it can be done with

Create Route for a specific URL without changing the URL with MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-01 18:20:11
I have a MVC Web Application that runs on www.domain.com and I need to configure a different URL binding for another domain www.domain2.com for the same web application. The new domain www.domain2.com will have to return a specific Controller Action View like /Category/Cars : routes.MapRoute( name: "www.domain2.com", url: "www.domain2.com", defaults: new { controller = "Category", action = "Cars", id = UrlParameter.Optional } ); How can I achieve this without changing the URL, so the visitor inserts the url www.domain2.com and receives the view www.domain.com/category/cars but the url remains

MVC5 : Attribute Routing Precedence Among Controllers

送分小仙女□ 提交于 2019-12-01 17:38:27
I am using the Attribute Routing from MVC5 in my controllers. Question: Is there a way to control attribute routing precedence among controllers? Consider the following [Route("home/{action=index}/{username?}")] public class HomeController : Controller { [Route("home/index/{username?}", Order = 1)] [Route("home/{username?}", Order = 2)] [Route("{username?}", Order = 3)] public ActionResult Index() { // ... bunch of stuff } } Base on the code above, HomeController.Index() action method should be invoked using the following requests: domain/ domain/{username} domain/home/ domain/home/{username}

Appending ?param= to mvc routes

一个人想着一个人 提交于 2019-12-01 16:56:43
Some MVC sites have querystring params appended to the route Url (of which I noticed StackOverflow does), such as: https://stackoverflow.com/questions/tagged/java ?page=9802&sort=newest&pagesize=15 What are the advantages of having the parameters as more conventional ?querystring params, rather than /param/values/ ? Also, how are these params appended to routes that have been set up? I'm familiar with setting up mvc routes with params like "users/details/{id}" etc. but don't know how to configure routes for use with 1 or more ?params as per the example url above? Query string parameters are