asp.net-web-api2

Order of execution with multiple filters in web api

别等时光非礼了梦想. 提交于 2019-11-27 06:33:34
I am using latest web api . I do annotate some controllers with 3 different filter attributes. 1 [Authorize] 2 [RessourceOwnerAttribute derived from AuthorizationFilterAttribute] 3 [InvalidModelStateAttribute derived from ActionFilterAttribute] I can not be sure that the filters run in the order they are declared from top to down. How do I define the order of execution in web api 2.1 ? https://aspnetwebstack.codeplex.com/workitem/1065# http://aspnet.uservoice.com/forums/147201-asp-net-web-api/suggestions/3346720-execution-order-of-mvc4-webapi-action-filters Do I still have to fix that for

Handling Dates with OData v4, EF6 and Web API v2.2

一曲冷凌霜 提交于 2019-11-27 06:08:21
问题 I'm in the midst of upgrading from v1-3 to v4, but I've run into a few problems. My understanding is that DateTime is unsupported, and I have to always use DateTimeOffset. Fine. But before I was storing Sql date data type in the DateTime, now it seems I get this error: Member Mapping specified is not valid. The type 'Edm.DateTimeOffset[Nullable=False,DefaultValue=,Precision=]' of member 'CreatedDate' in type 'MyEntity' is not compatible with 'SqlServer.date[Nullable=False,DefaultValue=

Default model example in Swashbuckle (Swagger)

℡╲_俬逩灬. 提交于 2019-11-27 05:35:34
问题 I'm running ASP WebAPI 2 and successfully installed Swashbuckle. I am trying to figure out how one defines what the default schema values are? For example, on the Swagger live demo site they changed the default value of pet to "doggie". They also defined the allowable values for status. (Live Demo) 回答1: Well the code of vgaspar.trivix did not work completly for me, the default values did not get set for the schema. Also i got an NullPointerException . I managed to get it working as intended

MVC 5 Web API with Facebook access token to RegisterExternal without need of Cookie

走远了吗. 提交于 2019-11-27 05:20:29
问题 Setup: New MVC5 Project with just Web API. Added Facebook AppId and Secret. I can get Token for my Web API from Token endpoint by passing in UserName and Password. Then use that token for further calls. BUT I want to register new users with the help of Facebook SDK in iOS app. I am using Facebook SDK to get Access Token. (Assume at this point, I have an Access Token). Next thing I know is to call api/Account/RegisterExternal endpoint by passing this token in Authorization header with Bearer

How do I unit test web api action method when it returns IHttpActionResult?

試著忘記壹切 提交于 2019-11-27 04:58:20
问题 Let's assume this is my action method public IHttpActionResult Get(int id) { var status = GetSomething(id); if (status) { return Ok(); } else { return NotFound(); } } Test will be var httpActionResult = controller.Get(1); How do I check my http status code after this? 回答1: Here Ok() is just a helper for the type OkResult which sets the response status to be HttpStatusCode.Ok ...so you can just check if the instance of your action result is an OkResult ...some examples(written in XUnit ): //

Angular2 HTTP Post ASP.NET MVC Web API

瘦欲@ 提交于 2019-11-27 04:41:30
问题 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) {

Web Api: recommended way to return json string

孤街浪徒 提交于 2019-11-27 04:06:31
问题 I've got a couple of services which already receive a json string (not an object) that must be returned to the client. Currently, I'm creating the HttpResponseMessage explicitly and setting its Content property to the json string which the service receives: var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(jsonUtilizadores, Encoding.UTF8, "application/json"); return response; Now, is there a better way of doing this with the new IHttpActionResult ?

How to configure SSL on a self hosted Web API in Azure Service Fabric

爱⌒轻易说出口 提交于 2019-11-27 03:41:34
问题 I have followed this article to setup an OWIN self hosted Web API within an Azure service fabric stateless service. I also found this article which describes setting up an HTTPS endpoint within an Azure service fabric service. ... <Certificates> <EndpointCertificate Name="TestCert1" X509FindValue="FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0" X509StoreName="MY" /> </Certificates> ... How do I configure the SSL certificate for my WebAPI service within service fabric? When I

How to inject ApplicationUserManager with unity

好久不见. 提交于 2019-11-27 03:34:46
问题 I have ApplicationUserManager defined like this: public class ApplicationUserManager : UserManager<ApplicationUser, int> { public ApplicationUserManager(IUserStore<ApplicationUser, int> store) : base(store) { } public override Task<IdentityResult> CreateAsync(ApplicationUser user, string password) { var result = base.CreateAsync(user, password); //... Repository.DoSomething(...); //Repository is null here //.. } [Dependency] public IRepository Repository { get; set; } } For some reason my

ASP.NET WEB API 2 OWIN Authentication unsuported grant_Type

孤者浪人 提交于 2019-11-27 03:33:15
问题 Hi I am trying to set up OAuth bearrer token authentication in my ASP.NET Web API 2 project. I have two project one will be the WEB API Project and the other a SPA project. Here is what I have done so far: I have created the OWIN Startup class: [assembly: OwinStartup(typeof(CodeArt.WebApi.App_Start.Startup))] namespace CodeArt.WebApi.App_Start { public class Startup { static Startup() { PublicClientId = "self"; UserManagerFactory = () => new UserManager<UserModel>(new UserStore<UserModel>());