ASP.Net Web API 项目基础配置

2018-11-28  本文已影响0人  JADDC
一、跨域、小驼峰配置

在App_Start 文件夹下的WebApiConfig.cs添加如下代码

        //Cors 跨域
        var allowOrigins = AppSettings.CorsAllowOrigins;
        var allowHeaders = AppSettings.CorsAllowHeaders;
        var allowMethods = AppSettings.CorsAllowMethods;
        var allowExposedHeaders = AppSettings.CorsAllowExposedHeaders;
        var globalCors = new EnableCorsAttribute(allowOrigins, allowHeaders, allowMethods, allowExposedHeaders);
        config.EnableCors(globalCors);
        
        //小驼峰设置
        config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

Web.config<appSettings>节点中添加跨域信息

      <!--Cors 跨域设置-->
      <add key="CorsAllowOrigins" value="*" />
      <add key="CorsAllowHeaders" value="*"/>
      <add key="CorsAllowMethods" value="*"/>
      <add key="CorsAllowExposedHeaders" value="*"/>

%AppData%\NuGet\

上一篇下一篇

猜你喜欢

热点阅读