asp.net-web-api2

WebAPI controller inheritance and attribute routing

浪子不回头ぞ 提交于 2019-12-28 06:45:42
问题 I have few controllers that inherit from the same base class. Among the different actions that they don't share with each other, they do have a few that are completely identical. I would like to have these on my base class because they all work completely the same it's just that they're accessed through different routes. How should I define these actions with several different routes? My inherited classes also have a RoutePrefixAttribute set on them so each of them is pointing to a different

Adding a custom query backed Navigation Property to ODataConventionModelBuilder

人走茶凉 提交于 2019-12-28 06:45:16
问题 Situation I created the following Model classes public class Car { public int Id {get;set;} public string Name {get;set;} public virtual ICollection<PartState> PartStates {get;set; } } public class PartState { public int Id {get;set;} public string State {get;set;} public int CarId {get;set;} public virtual Car Car {get;set;} public int PartId {get;set;} public virtual Part Part {get;set;} } public class Part { public int Id {get;set;} public string Name {get;set;} } And a matching DbContext

Adding a custom query backed Navigation Property to ODataConventionModelBuilder

↘锁芯ラ 提交于 2019-12-28 06:45:14
问题 Situation I created the following Model classes public class Car { public int Id {get;set;} public string Name {get;set;} public virtual ICollection<PartState> PartStates {get;set; } } public class PartState { public int Id {get;set;} public string State {get;set;} public int CarId {get;set;} public virtual Car Car {get;set;} public int PartId {get;set;} public virtual Part Part {get;set;} } public class Part { public int Id {get;set;} public string Name {get;set;} } And a matching DbContext

IIS Compilation Error -2146232576 AspNetInitializationExceptionModule

丶灬走出姿态 提交于 2019-12-28 05:32:04
问题 I have a fairly simple C# WebAPI2 project that runs locally but after publishing to IIS on a remote machine (Windows Server 2012 R2 Standard) the web page displays the following (after setting customErrors to "Off"): Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: The

Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3

淺唱寂寞╮ 提交于 2019-12-27 16:40:29
问题 I tried to follow the steps at http://enable-cors.org/server_aspnet.html to have my RESTful API (implemented with ASP.NET WebAPI2) work with cross origin requests (CORS Enabled). It's not working unless I modify the web.config. I installed WebApi Cors dependency: install-package Microsoft.AspNet.WebApi.Cors -ProjectName MyProject.Web.Api Then in my App_Start I've got the class WebApiConfig as follows: public static class WebApiConfig { public static void Register(HttpConfiguration config) {

rest web api 2 makes a call to action method without invoked

别等时光非礼了梦想. 提交于 2019-12-25 17:57:34
问题 I am following a tutorial located here: https://docs.asp.net/en/latest/tutorials/first-web-api.html and i am running the web api in iis express and call it using postman with the following path: http://localhost:5056/api/todo this call hits the constructor and then somehow calls the GetAll function which is never called and does not even have HttpGet verb. How is it getting called? namespace TodoApi.Controllers { [Route("api/[controller]")] public class TodoController : Controller { public

rest web api 2 makes a call to action method without invoked

风格不统一 提交于 2019-12-25 17:57:27
问题 I am following a tutorial located here: https://docs.asp.net/en/latest/tutorials/first-web-api.html and i am running the web api in iis express and call it using postman with the following path: http://localhost:5056/api/todo this call hits the constructor and then somehow calls the GetAll function which is never called and does not even have HttpGet verb. How is it getting called? namespace TodoApi.Controllers { [Route("api/[controller]")] public class TodoController : Controller { public

Can't figure out if OWIN is intercepting requests to api from client

心已入冬 提交于 2019-12-25 16:46:07
问题 I have an Asp.net webapi with JWT authentication using OWIN middle ware. My resource server and the authorization server are same. I am able to get the token from the token endpoint. ValidateClientAuthentication and GrantResourceOwnerCredentials methods are hit successfully. However when I try to access a protected(with [Authorize]) api (with authorization header set to bearer token) I only get "Authorization has been denied for this request". I have overridden ValidateAuthorizeRequest method

How to post an object from MVC controller to Web Api controller?

*爱你&永不变心* 提交于 2019-12-25 16:44:21
问题 Scenario is my MVC view is returning data to Controller action and from my action requirement is to build an object and pass it to an external Web API. I m getting data in my action and building an object as well. Can you please direct me how I should pass object to external Web API. Also should it be JSON, object or xml ? I m giving my controller and Web API code below: Controller action: public ActionResult Submit(FormCollection form) { Options lead = new Options(); lead.Situation = form

How to post an object from MVC controller to Web Api controller?

耗尽温柔 提交于 2019-12-25 16:43:29
问题 Scenario is my MVC view is returning data to Controller action and from my action requirement is to build an object and pass it to an external Web API. I m getting data in my action and building an object as well. Can you please direct me how I should pass object to external Web API. Also should it be JSON, object or xml ? I m giving my controller and Web API code below: Controller action: public ActionResult Submit(FormCollection form) { Options lead = new Options(); lead.Situation = form