Last active
July 5, 2017 22:46
-
-
Save danieldiazastudillo/254835a975e8e465f68dd2524392342c to your computer and use it in GitHub Desktop.
Configuración base para WebAPI2 con CORS y CamelCase por defecto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Http; | |
using Newtonsoft.Json.Serialization; | |
namespace PROYECTO.API | |
{ | |
public static class WebApiConfig | |
{ | |
public static void Register(HttpConfiguration config) | |
{ | |
//HABILITA CORS PARA TODA LA WEBAPI | |
config.EnableCors(); | |
//camelCase. Por defecto todas las propiedades serán retornadas al cliente en camelCase | |
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
// Web API routes | |
config.MapHttpAttributeRoutes(); | |
config.Routes.MapHttpRoute( | |
name: "DefaultApi", | |
routeTemplate: "api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional } | |
); | |
config.SuppressDefaultHostAuthentication(); //deshabilita autenticación por cookie SÓLO A LA WEBAPI | |
config.Filters.Add(new HostAuthenticationFilter("Bearer")); //Habilita tokens | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment