asp.net-web-api

Using ajaxSetup beforeSend for Basic Auth is breaking SignalR connection

拜拜、爱过 提交于 2020-01-12 05:23:26
问题 I have a WebApi secured with Basic Auth which is applied to the entire Api using a AuthorizationFilterAttribute. I also have SignalR Hubs sitting on several of my Api Controllers. Alongside this I have a web page which makes use of my WebApi. The web page is mostly written in Backbone, so in order to make calls to my secured WebApi, I have added the following jquery $.ajaxSetup({ beforeSend: function (jqXHR, settings) { jqXHR.setRequestHeader('Authorization', 'Basic ' + Token); return true; }

How to do dependency injection to Action Filter on ASP.NET Web API

扶醉桌前 提交于 2020-01-12 04:06:30
问题 I really get stuck on the approach to do dependency injection into action filter of web api. I have an action filter like this: public class AuthorizationAttribute : ActionFilterAttribute { public IApiKeyRepository Repository { get; set; } private Guid GetApiKey(string customerKey) { return Repository.GetApiKey(customerKey); } public override void OnActionExecuting(HttpActionContext actionContext) { } } I would like to do property injection on the property Repository by using Windsor (but it

How to do dependency injection to Action Filter on ASP.NET Web API

為{幸葍}努か 提交于 2020-01-12 04:06:29
问题 I really get stuck on the approach to do dependency injection into action filter of web api. I have an action filter like this: public class AuthorizationAttribute : ActionFilterAttribute { public IApiKeyRepository Repository { get; set; } private Guid GetApiKey(string customerKey) { return Repository.GetApiKey(customerKey); } public override void OnActionExecuting(HttpActionContext actionContext) { } } I would like to do property injection on the property Repository by using Windsor (but it

Dependency injection for ASP.NET Web API action method parameters

泪湿孤枕 提交于 2020-01-12 03:31:37
问题 I am working on an ASP.NET Web API project in C# for a JSON interface to a mobile application. My idea was to create interfaces for all requests and then only use these interfaces in the Web API code. I ended up with something like this: public interface IApiObject {} public interface IApiResponse<T> : IApiObject where T : IApiObject {} public interface IApiRegistrationRequest : IApiObject {} My controller looks like this: public class MyApiController : ApiController { public IApiResponse

But Seriously… Example of ASP.NET WebAPI implementation including OAuth

时光毁灭记忆、已成空白 提交于 2020-01-12 03:24:03
问题 I'm really not interested in WCF samples. The DotNetOpenAuth implementations that I found are also incomplete or assume WCF. I've found Thinkitecture.IdentityServer.45 which is anything but lightweight and isn't really appropriate for building into my new WebAPI project. I even found the Oauth2DotNet project that has almost no real information. Microsoft has posted a few Oauth/OpenID related projects, but I can't even find proper documentation for these either. My project: Create a new site

Use External Access Token or Local Access Token

此生再无相见时 提交于 2020-01-11 19:57:35
问题 I am developing an application using ASP.NET MVC 5.2.2, Web API 2.2 and Katana/OWIN 3.0 . The application uses ASP.NET Identity 2.1 for local accounts and database. I am using OAuth Authorization Server to generate access and refresh token. I have Android and IOS apps which uses my local oauth authorization server. Android and IOS apps uses SDK to login with Facebook, Google, etc. After that the apps will send the (Facebook/Google/etc) access token to the server. The server will validate

Use External Access Token or Local Access Token

爱⌒轻易说出口 提交于 2020-01-11 19:56:32
问题 I am developing an application using ASP.NET MVC 5.2.2, Web API 2.2 and Katana/OWIN 3.0 . The application uses ASP.NET Identity 2.1 for local accounts and database. I am using OAuth Authorization Server to generate access and refresh token. I have Android and IOS apps which uses my local oauth authorization server. Android and IOS apps uses SDK to login with Facebook, Google, etc. After that the apps will send the (Facebook/Google/etc) access token to the server. The server will validate

Authorization has been denied for this request - New Web API Project

亡梦爱人 提交于 2020-01-11 15:06:22
问题 I just created new Web API project (using MVC) in visual studio 2015 and for the testing purpose, I ran that project but ended up below error. After running the project, it brings up Home Page correctly but when I navigated to /api/values or /api/values/5, it gives me below xml message. <Error> <Message>Authorization has been denied for this request.</Message> </Error> Can someone please help? I am new to Web API. Please note that I don't want to remove the Authorize attribute. I would like

How to use enums with EnumMember attribute in FromBody ViewModel in Web API Request?

孤街醉人 提交于 2020-01-11 13:35:09
问题 I'm trying to implement an HttpPost method in an ASP.NET Core Web API project with a [FromBody] view model and enums. In the past, binding view models with the [FromBody] attribute worked well. In my particular scenario, I want to offer a JSON endpoint where I convert a given value into a C# enum with different names. This example should explain what I want to achieve: public enum WeatherEnum { [EnumMember(Value = "good")] Good, [EnumMember(Value = "bad")] Bad } Internally, I want to use

How to add client certificate in ASP.NET Web API in-memory testing?

假装没事ソ 提交于 2020-01-11 10:41:52
问题 I want to test my Web API service using in-memory HttpServer . The current setup looks the following: var httpConfig = CreateTestHttpConfiguration(); var server = new HttpServer(httpConfig); var handler = new WebRequestHandler(); var cert = new X509Certificate2("filename", "password"); handler.ClientCertificates.Add(cert); var client = HttpClientFactory.Create(handler, server); I can make requests to the server using these client and everything works except that certificate is not added to