attributerouting

Is Attribute Routing possible in Azure Functions

泄露秘密 提交于 2019-12-04 06:41:36
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/246fb962-604d-4699-9443-fa3fa840e9eb/ Am i missing some thing? Cannot we enforce route parameter to be guid

Specify default controller/action route in WebAPI using AttributeRouting

只愿长相守 提交于 2019-12-04 03:50:34
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 = "Index", id = UrlParameter.Optional } //); } } If I comment the section above and try to run the webapi app,

Web Api Controller in other project, route attribute not working

旧街凉风 提交于 2019-12-03 23:12:13
I have a solution with two projects. One Web Api bootstap project and the other is a class library. The class library contains a ApiController with attribute routing. I add a reference from web api project to the class library and expect this to just work. The routing in the web api is configured: config.MapHttpAttributeRoutes(); The controller is simple and looks like: public class AlertApiController:ApiController { [Route("alert")] [HttpGet] public HttpResponseMessage GetAlert() { return Request.CreateResponse<string>(HttpStatusCode.OK, "alert"); } } But I get a 404 when going to the url "

Attribute routing with http PUT method constraint

好久不见. 提交于 2019-12-03 17:17:49
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 return View(); } [HttpPut] [Route("update")] public ActionResult Update() { // this does not work return

How can I generate a WebApi2 URL without specifying a Name on the Route attribute with AttributeRouting?

帅比萌擦擦* 提交于 2019-12-03 16:16:31
问题 I've configured my ASP.NET MVC5 application to use AttributeRouting for WebApi: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); } } I have an ApiController as follows: [RoutePrefix("api/v1/subjects")] public class SubjectsController : ApiController { [Route("search")] [HttpPost] public SearchResultsViewModel Search(SearchCriteriaViewModel criteria) { //... } } I would like to generate a URL to my WebApi controller

OWIN cannot run multiple apps in isolation using webapp.start

冷暖自知 提交于 2019-12-03 16:00:05
When I try and start two apps on different url's, I get problems with attribute routing middleware. If I have two similar routes in seperate apps but with different http methods web.api seems find only one of the methods. Microsoft.Owin.Hosting.WebApp.Start<Admin.Startup>("http://localhost:1000"); Microsoft.Owin.Hosting.WebApp.Start<Startup>("http://localhost:1001"); How can I isolate both apps so that attribute routing don't conflict? Based on your last comment, an example below to filter out the assemblies: config.Services.Replace(typeof(IAssembliesResolver), new CustomAssembliesResolver());

Multiple controllers with same URL routes but different HTTP methods

旧街凉风 提交于 2019-12-03 14:11:58
I've got a following two controllers: [RoutePrefix("/some-resources") class CreationController : ApiController { [HttpPost, Route] public ... CreateResource(CreateData input) { // ... } } [RoutePrefix("/some-resources") class DisplayController : ApiController { [HttpGet, Route] public ... ListAllResources() { // ... } [HttpGet, Route("{publicKey:guid}"] public ... ShowSingleResource(Guid publicKey) { // ... } } All three actions got in fact three different routes: GET /some-resources POST /some-resources GET /some-resources/aaaaa-bbb-ccc-dddd If I put them into single controller everything

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

前提是你 提交于 2019-12-03 10:23:33
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 error message involve configuring membership providers in the web.config file. This project has neither

How can I generate a WebApi2 URL without specifying a Name on the Route attribute with AttributeRouting?

巧了我就是萌 提交于 2019-12-03 04:43:48
I've configured my ASP.NET MVC5 application to use AttributeRouting for WebApi: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); } } I have an ApiController as follows: [RoutePrefix("api/v1/subjects")] public class SubjectsController : ApiController { [Route("search")] [HttpPost] public SearchResultsViewModel Search(SearchCriteriaViewModel criteria) { //... } } I would like to generate a URL to my WebApi controller action without having to specify an explicit route name. According to this page on CodePlex , all MVC

how to add default parameters to attribute routes in asp.net mvc

假装没事ソ 提交于 2019-12-02 02:08:52
问题 I am trying to change this convention based route: routes.MapRoute( "MovieByReleaseDate", "movies/released/{year}/{month}", new { controller = "Movies", action = "ByReleasedDate" }, ); to attribute route: [Route("movies/released/{year}/{month}")] but I can't see how I can define default parameters like in the first way. 回答1: You can use multiple [Route] attributes coupled with nullable parameters to achieve your goal. [HttpGet] [Route("movies/released/")] [Route("movies/released/{year}")]