IIS突然给了我错误的物理路径。它曾经工作过。 Asp.Net

时间:2019-03-19 12:59:06

标签: asp.net .net iis asp.net-web-api .net-4.0

从现在开始我在项目中工作了一段时间,我的IIS和WebAPI配置都已设置好。当我要测试一个新的端点时,我所有的端点都无法正常工作,我什至不知道为什么。 以前效果很好,我没有在配置中进行任何更改

Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=301879
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
  </system.web>
  <!-- Para validar put e delete-->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <!-- <add name="CoreEntities" connectionString="metadata=res://*/Data.CoreDB.csdl|res://*/Data.CoreDB.ssdl|res://*/Data.CoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*********;initial catalog=clone;persist security info=True;user id=***********;password=********;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />--><!--<add name="CoreEntities" connectionString="metadata=res://*/Data.CoreDB.csdl|res://*/Data.CoreDB.ssdl|res://*/Data.CoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*********;initial catalog=core;user id=******;password=*******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>-->
    <add name="CoreEntities" connectionString="metadata=res://*/Data.CoreDB.csdl|res://*/Data.CoreDB.ssdl|res://*/Data.CoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*******;initial catalog=corepetro;user id=**********;password=*******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="cloneEntities" connectionString="metadata=res://*/Data.CoreTestDB.csdl|res://*/Data.CoreTestDB.ssdl|res://*/Data.CoreTestDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*********;initial catalog=clone;persist security info=True;user id=******;password=*******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <!--<add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
      <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, Authorization" />-->
    </customHeaders>
  </httpProtocol>
  <handlers>
    <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" />
  </handlers>
</system.webServer>
</configuration>

Global.asax.cs

namespace clubpetroapi
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
    }
}

RouteConfig:

namespace clubpetroapi
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

我要访问的控制器:

 public class RulesFraudCrontroller : ApiController 
    {
        [EnableCors(origins: "*", headers: "*", methods: "*")]
        [Route("rules")]
        [HttpPost]
        public IHttpActionResult InsertRule([FromUri] string idstore, [FromUri] string token)
        {
            try
            {
                var rule = new Data.TB_RULES_FRAUD();
                var service = new Services.RulesFraudService();
                var response = service.InsertRule(idstore,rule, token);
                switch (response.Cod)
                {
                    case 200: return Ok(response.Obj); //Usuário desativado
                    case 400: return new StatusCodeResult(HttpStatusCode.BadRequest, this); //Solicitação inválida
                    case 401: return new StatusCodeResult(HttpStatusCode.Unauthorized, this); //Sem permissão
                    case 403: return new StatusCodeResult(HttpStatusCode.Forbidden, this);
                    case 404: return new StatusCodeResult(HttpStatusCode.NotFound, this); //Usuário não encontrado
                    case 405: return new StatusCodeResult(HttpStatusCode.MethodNotAllowed, this); //metodo não permitido
                    case 500: return new StatusCodeResult(HttpStatusCode.InternalServerError, this); //Erro interno de servidor
                    default: return InternalServerError();
                }


            }
            catch (Exception E)
            {
                return InternalServerError(E);
            }
        }

    }

当我尝试使用该地址作为POST方法访问我的端点时:

localhost:56495 / rules?idstore = 2&token = master

它给了我以下页面,对不起葡萄牙语:

Image.

请注意正在尝试到达的物理路径,它不应该那样,但我不知道如何解决。

我正在使用.net Framework 4.6.1

2 个答案:

答案 0 :(得分:0)

您使用HttpPost。如果使用HttpPost,则不会请求查询字符串(localhost:56495 / rules?idstore = 2&token = master)。您应该使用HttpGet。或者,您可以尝试通过邮递员发送HttpPost请求。

答案 1 :(得分:0)

您是否尝试过将端点更改为“ GET”,并在该端点上放置调试点,以查看是否被击中?