asp.net-web-api2

Reuse existing ASP.NET-MVC 5 Identity 2 authorization for WEB API OData controllers to make it easy to login for other apps?

梦想的初衷 提交于 2019-12-12 13:04:32
问题 I have complete ASP.NET-MVC5 application which I extended by the WEB API 2 OData controllers. For instance I have: public class PersonController : ODataController and MVC controller which demands authorization [Authorize] public class PersonController : Controller Both contollers use ApplicationDbContext where my DbSets are I don't want to give data about person to everyone in the world through WEB API controller. I already have User , Moderator and Admin roles in my MVC application. Can I

What is the correct way to return an “empty task” when implementing message handlers such as IExceptionHandler or IExceptionLogger in F#?

霸气de小男生 提交于 2019-12-12 12:31:47
问题 In C# when implementing these handlers I would do something similar to this, public class DefaultExceptionHandler : IExceptionHandler { public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) { context.Result = new ErrorActionResult(context.Request, context.Exception); return Task.FromResult(0); } } When implementing the same interface in F# I did the following, type DefaultExceptionHandler() = let mapExceptionTypetoHttpStatusCode (ex:Exception) :

WebAPI passed post parameters is null

て烟熏妆下的殇ゞ 提交于 2019-12-12 12:11:51
问题 I'm testing with WebAPI 2 and I have created the following controller method. // POST api/values public string Post([FromBody] string value) { string returnValue = "Return: " + value ; return returnValue; } When i'm posting the following message with fiddler the method parameter keep returning null. POST http://localhost:50814/api/Values/ HTTP/1.1 Host: localhost:50814 Content-Type: application/json Content-Length: 14 {value: "New"} I have simplyfied my code already as much as i can but still

ApiController extension method - can't access ResponseMessage

左心房为你撑大大i 提交于 2019-12-12 11:52:28
问题 I want to create extension method for ApiController to be able to return custom content. My idea is to return custom error with my own details. I want to return custom error similar to errors returned by OAuthAuthorizationServerProvider : { "error": "invalid_grant", "error_description": "You have 3 more attempts before Your account will be locked." } Inside my ApiController I've added this method: public IHttpActionResult Test() { HttpError err = new HttpError(); err["error"] = "40001"; err[

405 Method Not Allowed Web API 2

做~自己de王妃 提交于 2019-12-12 09:39:29
问题 I've been through just about every article I can find, on SO and more. I've made changes to the Web.config to meet the answers as they all seem to point to removing the WebDAV module and handler. However, I'm still getting the error: 405 Method Not Allowed The requested resource does not support http method 'PUT'. NOTE: this was originally just an MVC 4 project. I've added artifacts to support Web API. Seems like it's possible I may have missed something. NOTE: the GET calls are working just

Libsodium-net - Unable to load DLL 'libsodium.dll

左心房为你撑大大i 提交于 2019-12-12 08:39:16
问题 I installed Libsodium-net through NuGet and am able to include Sodium in my classes, but when I try to run it, I get An exception of type 'System.DllNotFoundException' occurred in Sodium.dll but was not handled in user code Additional information: Unable to load DLL 'libsodium.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) I am just trying to run the sample code from the gitbooks documentation https://bitbeans.gitbooks.io/libsodium-net/content/password

WebApp.Start<TStartup> Method Type Parameter

五迷三道 提交于 2019-12-12 07:45:38
问题 In setting up my Windows Service application to self host using Owin based on this article: http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api I used this overload of the WebApp.Start method: WebApp.Start Method (String) Here is my code: //(in startup method) _server = WebApp.Start<Startup>(BaseAddress); public class Startup { // This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void

Ninject error in WebAPI 2.1 - Make sure that the controller has a parameterless public constructor

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:44:45
问题 I have the following packages and their dependencies installed in my WebAPI project: Ninject.Web.WebApi Ninject.Web.WebApi.OwinHost I am running this purely as a web-api project. No MVC. When I run my application and send a POST to the AccountController's Register action I get the following error returned: { "message":"An error has occurred.", "exceptionMessage":"An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless

How to debug/unit test webAPi in one solution

我只是一个虾纸丫 提交于 2019-12-12 07:44:42
问题 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

Unloaded “eager-loaded” properties causing issues when returning json'd data

心已入冬 提交于 2019-12-12 07:27:06
问题 Hopefully the title makes sense, I'll do my best to describe my problem. I'm currently developing an ASP.NET Web API. In my "Company" controller I have a GetCompany() action. /// <summary> /// Gets the 'Authorization-Token' request header and finds the company with the /// matching decrypted token from the database, returns it; if null, returns 404 /// </summary> /// <returns>Matching company for token passed in request or 404 if null</returns> [HttpGet][ResponseType(typeof(Company))] [Route(