C# – Enable CORS in Web API 2

Lets enable CORS in Web API 2 Use Nuget, Step (1). Go to: TOOLS > Library Package Manager > Package Manager Console, and type in: Install-Package Microsoft.AspNet.WebApi.Cors Step (2). Add these line in WebApiConfig.cs file which is inside App_Start folder public static void Register(HttpConfiguration config) { //enable cores var enableCorsAttribute = new EnableCorsAttribute(“*”,”Origin, Content-Type, Accept”,”GET, Read More

Add Query String token for web api authentication

Create this class to retrieve access token from query string and add to ApplicationOAuthProvider.cs public class QueryStringOAuthBearerProvider : OAuthBearerAuthenticationProvider { public override Task RequestToken(OAuthRequestTokenContext context) { var value = context.Request.Query.Get(“access_token”); if (!string.IsNullOrEmpty(value)) { context.Token = value; } return Task.FromResult<object>(null); } } Edit this code in Startup.Auth.cs OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString(“/Token”), Provider Read More