IIS突然给了我错误的pysical路径。以前工作过。 Asp.Net

问题描述 投票:-1回答:2

我从现在开始工作了一段时间,我的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方法访问我的端点时:

本地主机:56495 /规则idstore = 2&标记=主

它给了我以下页面,抱歉葡萄牙语:

Image.

请注意尝试访问的物理路径,它不应该是这样,但我不知道如何解决它。

我正在使用.net框架4.6.1

asp.net .net iis asp.net-web-api .net-4.0
2个回答
0
投票

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


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.