attributerouting

Attribute routing to controller action isn't working in ASP.NET Core

二次信任 提交于 2019-12-12 02:26:46
问题 I've set breakpoints, and followed the flow. The controller is being instantiated, and the parameters are being validated (I have some Data Annotations set up), but the controller method itself isn't being invoked. I think the problem is routing, but I'm not sure where it might be broken. I haven't set up any global routing; everything is done via attributes. The Swagger docs are being generating, too, and documenting the controller endpoints. In fact, everything seems to work OK on the

ASP.NET MVC path with file extension

白昼怎懂夜的黑 提交于 2019-12-11 03:57:54
问题 In ASP.NET MVC5 using attribute-based routing, I want to handle URLs with file extensions, eg ~/javascript/security.js Here's an example controller action method: [Route("javascript/security.js")] public ActionResult AngularSecurityModule(string clientId) { return View(new { ClientId = clientId }); } However, this gives me an HTTP 404 - Not Found. I'd prefer to not use runAllManagedModulesForAllRequests (eg <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> </system

Default area view cannot be found when using MVC 5 RouteArea attribute

梦想与她 提交于 2019-12-10 19:40:59
问题 I have an MVC5 project with multiple areas. I have a default area (named Default ) and within it, a default controller (named DefaultController ). This is accessible at site route. [RouteArea] public class DefaultController : Controller { [Route] public ActionResult Index() { return View("Index"); } } public static void RegisterRoutes(RouteCollection routes) { routes.LowercaseUrls = true; routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.MapRoute( name:

ASP.NET MVC 5 Attribute Routing: Url.Action returns null

為{幸葍}努か 提交于 2019-12-10 16:25:05
问题 I am experiencing an issue with a refactoring of our payment processing action method (called by our 3rd-party online payment provider). We have a product controller with the [Authorize] and [RoutePrefix("products")] attributes at the class level, and action methods including the following: Product(string contractNumber) with routing attribute [Route("{productCode}")] MakePayment(string productCode, PaymentAmountType? amountSelection, decimal? amountValue) with routing attribute [Route("

Map url text to boolean parameter with MVC attribute routing

依然范特西╮ 提交于 2019-12-10 11:52:16
问题 Given the following two urls: /employee/list/active /employee/list/inactive How do I map the active/inactive part of the url to a boolean action method parameter, active being true, inactive being false? [Route("employee/list")] public ActionResult List(bool? active = null) 回答1: The enum is a correct approach as it allows you to easily add new statuses in the future : [Route("employee/list/{status}")] public ActionResult List(status status) { ... } public enum status { active, inactive } Even

MVC 5 AttributeRouting Catch All

依然范特西╮ 提交于 2019-12-10 02:06:25
问题 How do I create a catch all route with the new Attribute routing in MVC I tried this: [Route("{pagenode}", Order = 999)] But when I have a named route like [Route("contact"] I get the "Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL." error. 回答1: You can't do this with Attribute routing, do this the MVC4 way: Map a route in your routemapper like this: routes.MapRoute("RouteName","{*url}",new {

Is Attribute Routing possible in Azure Functions

泪湿孤枕 提交于 2019-12-09 17:58:54
问题 I am trying to enforce a route parameter to be guid but getting below error "Exception while executing function: GetUser -> One or more errors occurred. -> Exception binding parameter 'req' -> Invalid cast from 'System.String' to 'System.Guid'." public static async Task<HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Admin, "get", Route = "GetUser/{userId:guid}")] HttpRequestMessage req, Guid userId, ILogger log) { } The request i am making is http://localhost:7071/api/GetUser

Specify default controller/action route in WebAPI using AttributeRouting

萝らか妹 提交于 2019-12-09 16:06:24
问题 How does one set the default controller to use when using AttributeRouting instead of the default RouteConfiguration that WebAPI uses. i.e. get rid of the commented code section since this is redundant when using AttribteRouting public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //routes.MapRoute( // name: "Default", // url: "{controller}/{action}/{id}", // defaults: new { controller = "Home", action =

Attribute routing with http PUT method constraint

99封情书 提交于 2019-12-09 13:42:06
问题 I'm using the new attribute routing with MVC5 and have gotten http GET and POST method constraints to work by adding the [HttpGet] and [HttpPost] attributes to my action methods. But when I add [HttpPut] I just get a 404 error page. Does anyone know what I need to do to get attribute routing working with http PUT ? See code below: [HttpGet] [Route("edit")] public ActionResult Edit() { // this works return View(); } [HttpPost] [Route("insert")] public ActionResult Insert() { // this works

MapMvcAttributeRoutes: This method cannot be called during the application's pre-start initialization phase

我们两清 提交于 2019-12-09 07:26:39
问题 I have a very simple test in a test project in a solution using ASP MVC V5 and attribute routing. Attribute routing and the MapMvcAttributeRoutes method are part of ASP MVC 5. [Test] public void HasRoutesInTable() { var routes = new RouteCollection(); routes.MapMvcAttributeRoutes(); Assert.That(routes.Count, Is.GreaterThan(0)); } This results in: System.InvalidOperationException : This method cannot be called during the applications pre-start initialization phase. Most of the answers to this