attributerouting

Using WebAPI in LINQPad?

本小妞迷上赌 提交于 2019-12-20 09:21:42
问题 When I tried to use the Selfhosted WebAPI in LINQPad, I just kept getting the same error that a controller for the class didn't exist. Do I have to create separate assemblies for the WebAPI (Controllers/Classes) and then reference them in my query? Here's the code I'm using #region namespaces using AttributeRouting; using AttributeRouting.Web.Http; using AttributeRouting.Web.Http.SelfHost; using System.Web.Http.SelfHost; using System.Web.Http.Routing; using System.Web.Http; #endregion public

Controller without the controller suffix

牧云@^-^@ 提交于 2019-12-20 02:38:07
问题 based on my design requirements, I will like to exclude the suffix 'Controller' from my controllers and replace it with 'Resource'. So that 'FundsController' will become 'FundsResource'. The problem is that I am not able to route to my specified actions by either convention based or attribute routing when I change replace the term 'Controller' and get an error saying that the controller with this name could not be found. How can I satisfy the above mentioned design requirement and also be

Using HttpClient to Send Dates in URL Using AttributeRouting

北慕城南 提交于 2019-12-19 19:43:33
问题 I'm having some problems getting a date range query accepted by my WebAPI. As as far as I can tell from everything I've read this should be working but I still get 400 Bad Request responses. My API route looks like this: [System.Web.Http.HttpGet] [GET("range/{start:datetime}/{end:datetime}")] public HttpResponseMessage Get(DateTime start, DateTime end) I'm using the AttributeRouting library and according to this page the URL I'm requesting should be fine. My request URL looks like this: http:

MVC5 : Attribute Routing Precedence Among Controllers

旧巷老猫 提交于 2019-12-19 18:56:33
问题 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

Getting “No type was found that matches the controller named 'SampleSlashBaseService'” when trying to use WebAPI

╄→гoц情女王★ 提交于 2019-12-18 05:43:17
问题 I have a webapi project with a base ApiController named SlashBaseService: [RouteArea("uBase")] public abstract class SlashBaseService : ApiController { } The resulting dll is used in a WebForms project so I also have a WebActivator class with the following code to generate routes: RouteTable.Routes.MapHttpAttributeRoutes(config => { // Get all services inheriting from SlashBaseService foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in assembly.GetTypes())

AttributeRouting not working with HttpConfiguration object for writing Integration tests

最后都变了- 提交于 2019-12-18 04:18:05
问题 I'm creating some integration tests following the ideas outlined here: http://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-memory-hosting/ When I try to register routes from a hand crafted HttpConfiguration object I'm getting the following error: "The constraint entry 'inboundHttpMethod' on the route with route template 'api/Contacts/{id}' must have a string value or be of a type which implements 'IHttpRouteConstraint'." Sample code: Controller: [RoutePrefix("api")]

CreatedAtRoute routing to different controller

狂风中的少年 提交于 2019-12-17 23:05:01
问题 I'm creating a new webapi using attribute routing to create a nested route as so: // PUT: api/Channels/5/Messages [ResponseType(typeof(void))] [Route("api/channels/{id}/messages")] public async Task<IHttpActionResult> PostChannelMessage(int id, Message message) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != message.ChannelId) { return BadRequest(); } db.Messages.Add(message); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = message.Id },

MVC Attribute Routing Not Working

房东的猫 提交于 2019-12-17 06:49:22
问题 I'm relatively new to the MVC framework but I do have a functioning Web Project with an API controller that utilizes AttributeRouting (NuGet package) - however, I'm starting another project and it just does not want to follow the routes I put in place. Controller: public class BlazrController : ApiController { private readonly BlazrDBContext dbContext = null; private readonly IAuthProvider authProvider = null; public const String HEADER_APIKEY = "apikey"; public const String HEADER_USERNAME =

405 when using AttributeRouting.PUTAttribute unless I also include HttpPutAttribute

a 夏天 提交于 2019-12-12 11:11:03
问题 We have an MVC project that I am attempting to update to include WebApi. In order to get the required routes we are using AttributeRouting. All the calls seem to be routing correctly except for [PUT] which returns a 405. I have simplified the controller and actions and still receive the error with the [PUT] unless I include [HttpPut] also. Not sure what I am missing. [RoutePrefix("api/Sites")] public class SitesController : BaseApiController { [POST("")] public bool CreateSite(SiteSignupArgs

RoutePrefix Order alternative for WebAPI 2

十年热恋 提交于 2019-12-12 04:56:51
问题 In WebAPI you can specify an Order in RouteAttribute to determine which order the routes are matched in. For example the below will match /other to GetOther before matching /blah to GetByName [HttpGet, Route("{name}", Order = 1)] public string GetByName(string name) { ... } [HttpGet, Route("other")] public string GetOther() { ... } How would I do the same but with RoutePrefix (which doesn't have an Order property)? If it did it would looks something like this: [RoutePrefix("foo", Order = 1)]