asp.net-web-api2

Post json data in body to web api

人盡茶涼 提交于 2019-12-03 13:53:06
I get always null value from body why ? I have no problem with using fiddler but postman is fail. I have a web api like that: [Route("api/account/GetToken/")] [System.Web.Http.HttpPost] public HttpResponseBody GetToken([FromBody] string value) { string result = value; } My postman data: and header: WebAPI is working as expected because you're telling it that you're sending this json object: { "username":"admin", "password":"admin" } Then you're asking it to deserialize it as a string which is impossible since it's not a valid JSON string. Solution 1: If you want to receive the actual JSON as

context.Request.User is null in OWIN OAuthAuthorizationServerProvider

不想你离开。 提交于 2019-12-03 13:50:51
问题 I'm trying to implement OAuth using OWIN for a Web API v2 endpoint on my local intranet. The API is hosted in IIS using built-in Windows Authentication. In short, this is what I want to happen. When I ask for my Token at /token Pull the WindowsPrincipal out of the OWIN context Use the SID from the WindowsPrincipal to look up some roles for this user in a SQL table. Create a new ClaimsIdentity that stores the username and roles Turn that into a Json Web Token (JWT) that I sent bak When I

Where is the information about the authorization token stored on the ASP.NET WEB API server?

天大地大妈咪最大 提交于 2019-12-03 13:49:06
问题 In my Web Api 2 Identity 2 application after user registration I have a single record in single table: AspNetUsers. I use the following http request to get token: POST https://localhost:44304/Token HTTP/1.1 Accept: application/json Content-type: application/x-www-form-urlencoded Accept-Encoding: gzip Content-Length: 68 Host: localhost:44304 Connection: Keep-Alive User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4) grant_type=password&username=somemail@gmail.com&password=123456 and I get the

Exception Handling in ASP.NET Web Api 2

前提是你 提交于 2019-12-03 13:36:11
Problem: I need to handle web api 2 exceptions and return a rich object with the correct status code (401 for Unauthorized, 404 for ContentNotFound, etc) and some extra information as the content. Moreover, I need the content to look like a serialized Exception object (have the message , exceptionMessage , stackTrace , ... properties). Suggested Solutions: Create custom exception classes and writing a custom exception filter to apply to any controller's action. this custom exception filters handles the exception thrown according to it's type (one of the custom exceptions that I've already

How to correctly unit test OData v6.0 controller?

拜拜、爱过 提交于 2019-12-03 13:29:48
I'm attempting to unit test out OData controllers, however the APIs changed and previously recommended methods I tried do not work - currently I'm getting No non-OData HTTP route registered. when trying to instantiate ODataQueryOptions to be passed into the Get method of the controller My current code (based on answers like this one ): [TestMethod()] public void RankingTest() { var serviceMock = new Mock<IVendorService>(); serviceMock.SetReturnsDefault<IEnumerable<Vendor>>(new List<Vendor>() { new Vendor() { id = "1" } }); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,

how to solve “HTTP Error 500.19 - Internal Server Error” “<remove name=”ExtensionlessUrlHandler-Integrated-4.0“ />”

跟風遠走 提交于 2019-12-03 13:05:07
i want to upload my webapi to iis but i am getting the following error Config Source: 24: </modules> 25: <handlers> 26: <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> here is my webconfig file <handlers> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <remove name="OPTIONSVerbHandler" /> <remove name="TRACEVerbHandler" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> i am using windows 8.1. i have installed all features of IIS. my

Visual Studio 2017 Localization Publish Settings

自作多情 提交于 2019-12-03 12:53:25
问题 This should be simple, but I haven't found a way to make this stop happening. Visual Studio publishes a lot of localized DLLs - It appears there is German localization, Spanish localization, Italian localization, french localization, Japanese localization, Russian localization and Korean localization. I have an ASP.NET Web API ODATA application, and when I publish the project using Visual Studio 2017, I have these localized dll's taking up unnecessary space in the bin folder. My application

How to access User in a service context in web API?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 11:55:11
If you are in a controller context, you can access the current authenticated User. Take an article such as Get the current user, within an ApiController action, without passing the userID as a parameter . However, if my controller calls a service (same assembly), but here I don't have the controller context. What is the best way to actually get the authenticated user? You can create an intermediate service to provide that functionality public interface IPrincipalProvider { IPrincipal User { get; } } public class WebApiPrincipalProvider : IPrincipalProvider { public IPrincipal User { get {

How to debug/unit test webAPi in one solution

隐身守侯 提交于 2019-12-03 11:45:19
Is there a way to unit test or debug a web api in one vs solution? I am consuming the WebAPI using HttpClient and have two instances of VS up to do this. in 1 VS instance I have the unit test, in the second vs instance I have the webapi running in localhost. Is there a better way to do this? Is the preferred way to unit test is to have a reference to the WebAPI project? I want to consume it using httpClient and not have to reference it in the UnitTest Project. so in my UnitTest method it would have a baseAddress of " http://localhost:1234 " this would be where the WebAPI if launched from the

How to integrate Autofac with WepApi 2 and Owin?

风流意气都作罢 提交于 2019-12-03 10:54:57
问题 I am using this package to integrate Autofac with my WebApi Owin application: https://www.nuget.org/packages/Autofac.WebApi2.Owin And following this post: http://alexmg.com/owin-support-for-the-web-api-2-and-mvc-5-integrations-in-autofac/ My code in Startup.cs looks like this: var config = new HttpConfiguration(); IContainer container = EngineContext.InitializeEngine(); var dependencyResolver = new AutofacWebApiDependencyResolver(container); config.DependencyResolver = dependencyResolver; app