• 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 }
        //);
    }
    

      

  • 相关阅读:
    按钮,文本框
    d01
    第一天,对于课程和工作的了解
    javaweb概念性知识
    Jdbc概念性知识
    连接数据库,和数据增删改
    oracle基础概念性知识
    面向对象java知识汇总题
    javaweb
    date日期
  • 原文地址:https://www.cnblogs.com/yanzhen/p/9105299.html
Copyright © 2020-2023  润新知