asp.net-web-api2

How to prevent a single object property from being converted to a DateTime when it is a string

独自空忆成欢 提交于 2019-11-28 02:20:46
问题 Here is a simplified version of the model I have to work with: class InputModel { public string Name { get; set; } public object Value { get; set; } } And the relevant parts of the controller: class Controller : ApiController { [HttpPut] public async Task<IHttpActionResult> Update([FromBody]InputModel model) { //implementation } } the Value property of the InputModel class could be of any type, and which type it will be is only known later on, in a piece of legacy code the model is sent to

WebAPI controller inheritance and attribute routing

点点圈 提交于 2019-11-28 01:03:55
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 route. Example I have base abstract class called Vehicle and then inherited Car , Bike , Bus etc. All

SwashBuckle/Swagger - OAuth Resource Owner Password Flow

有些话、适合烂在心里 提交于 2019-11-28 00:49:19
问题 I'm trying to implement swagger into my Asp.Net Web API, and i'm running into a problem. I'm using the password resource owner flow, and i'm having to add a work around in order to do this, which is covered in the following stack overflow question :- Swagger/Swashbuckle: OAuth2 with Resource Owner Password Credentials Grant I've got everything working, the Bearer token is added via javascript to the request header in the current browser window, but the api calls to the controller methods

Angular2 HTTP Post ASP.NET MVC Web API

主宰稳场 提交于 2019-11-27 23:44:09
How do you properly create a Web API POST of complex object or multiple parameters using Angular2? I have a service component in Angular2 as seen below: public signin(inputEmail: string, inputPassword: string): Observable<Response> { return this.http.post('/api/account/signin', JSON.stringify({ Email: inputEmail, Password: inputPassword}), this.options); } The targeted web api is seen below: [HttpPost] [Route("signin")] public async Task<IActionResult> Signin(string email, string password) { .... } This does not work because I need to convert the parameters of the web api into a single POCO

Build JSON response in Web API controller

不羁的心 提交于 2019-11-27 23:12:34
问题 In a WebAPI project, i have a controller that checks a status of a product, based on a value the user enters. Lets say they enter "123" and the response should be "status": 1, AND a list of products. If they enter "321" the "status" is 0, AND a list of products. My question is, how do i build such a string correct in a WebAPI controller. [Route("{value:int}")] public string GetProducts(int value) { var json = ""; var products = db.Products; if (products.Any()) { foreach (var s in products) {

User (IPrincipal) not available on ApiController's constructor using Web Api 2.1 and Owin

五迷三道 提交于 2019-11-27 21:21:45
问题 I am Using Web Api 2.1 with Asp.Net Identity 2. I am trying to get the authenticated User on my ApiController's constructor (I am using AutoFac to inject my dependencies), but the User shows as not authenticated when the constructor is called. I am trying to get the User so I can generate Audit information for any DB write-operations. A few things I'm doing that can help on the diagnosis: I am using only app.UseOAuthBearerTokens as authentication with Asp.Net Identity 2. This means that I

AspNet Identity 2: Customize OAuth endpoint response

 ̄綄美尐妖づ 提交于 2019-11-27 20:40:38
问题 I successfully implemented my custom OAuthAuthorizationServerProvider . But when I log in and retrieve a token, my client doesn't have any idea of the user's roles, claims, etc. I currently added a webapi controller to return the list of the principal's claims, but I'm not really happy with that. When requesting a token, the current response looks like: { access_token: "qefelgrebjhzefilrgo4583535", token_type: "bearer", expires_in: 59 } Q> How can make it return something like the following

Asp.net core MVC post parameter always null

耗尽温柔 提交于 2019-11-27 20:37:22
I am new to MVC core. I have created a project with MVC core which has a controller. This controller has Get and Post action methods. If i pass data to Get method using query string it works fine, but when i pass complex JSON to post method, then it always shows me null. Here what i am doing: Post Request URL: http://localhost:1001/api/users Content-Type: application/json Body: { "Name":"UserName", "Gender":"Gender of the user", "PhoneNumber":"PhoneNumber of the user" } Here is the Post action method [HttpPost] [Route("api/users")] public async Task<IActionResult> Post([FromBody]User newUser)

IIS Compilation Error -2146232576 AspNetInitializationExceptionModule

血红的双手。 提交于 2019-11-27 20:06:06
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 compiler failed with error code -2146232576. If I grab the detailed compiler output and run it on the IIS

DB-First authentication confusion with ASP.NET Web API 2 + EF6

China☆狼群 提交于 2019-11-27 19:09:25
I need to create a Web API C# application for an existing MySQL database. I've managed to use Entity Framework 6 to bind every database table to a RESTful API (that allows CRUD operations) . I want to implement a login/registration system (so that I can implement roles and permissions in the future, and restrict certain API requests) . The MySQL database I have to use has a table for users (called user ) that has the following self-explanatory columns: id email username password_hash It seems that the de-facto standard for authentication is ASP.Net Identity. I have spent the last hour trying