zoukankan      html  css  js  c++  java
  • webAPI 405

    web.config 配置

      <system.webServer>
        <modules>
          <remove name="WebDAVModule" />
        </modules>
        <handlers>
          <remove name="WebDAV" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
          <!--<add name="WebDAV" path="*" verb="PROPFIND,PROPPATCH,MKCOL,PUT,COPY,DELETE,MOVE,LOCK,UNLOCK" modules="WebDAVModule" resourceType="Unspecified" requireAccess="None" />-->
        </handlers>
      </system.webServer>
    

     

      <appSettings>
        <add key="cors-origins" value="http://www.liuyanzhen.com" />
        <add key="cors-headers" value="*" />
        <add key="cors-methods" value="GET,POST,DELETE,PUT" />
      </appSettings>
    

      

    WebApiConfig.cs 配置

    public static void Register(HttpConfiguration config)
    {
        // Web API 配置和服务
        config.EnableCors(new EnableCorsAttribute(
                ConfigurationTool.AppSetting("cors-origins"),
                ConfigurationTool.AppSetting("cors-headers"),
                ConfigurationTool.AppSetting("cors-methods")
            ));
    
        // Web API 路由
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
            name: "DefaultApiAction",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        //config.Routes.MapHttpRoute(
        //    name: "DefaultApi",
        //    routeTemplate: "api/{controller}/{id}",
        //    defaults: new { id = RouteParameter.Optional }
        //);
    }
    

      

  • 相关阅读:
    UVA 11859
    [OpenGL]OpenGL坐标系和坐标变换
    树状数组
    编程算法
    乞讨 间隔[a,b]在见面p^k*q*^m(k&gt;m)中数号码
    解析Android的 消息传递机制Handler
    Atitit.故障排除系列---php 计划网站数据库错误排除过程
    Remove Element
    [Angular Directive] Write a Structural Directive in Angular 2
    [Compose] 18. Maintaining structure whilst asyncing
  • 原文地址:https://www.cnblogs.com/yanzhen/p/9105299.html
Copyright © 2011-2022 走看看