【问题标题】:IIS is giving me wrong pysical path suddenly. It worked before. Asp.NetIIS 突然给了我错误的物理路径。它以前工作过。网络
【发布时间】:2019-08-10 00:27:13
【问题描述】:

我在我的项目中工作了一段时间,我的 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);
        }
    }
}

路由配置:

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 框架 4.6.1

【问题讨论】:

  • “注意试图到达的物理路径,它不应该是这样的”,那么你期望的路径是什么?为什么不能修改 IIS 配置以使其正确?
  • 如何更改 IIS express 的 de 配置?
  • 要么学习如何手动编辑配置文件,要么使用 Jexus Manager 之类的工具,docs.jexusmanager.com/getting-started/features.html
  • 你们没有抓住重点。我的一些端点工作,现在一些不工作。我没有改变任何东西。

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


【解决方案1】:

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

【讨论】:

  • 这就是我想要做的,即使它给了我错误 404。
  • 好的。尝试这个。 localhost:56495/RulesFraud/rules?idstore=2&token=master
  • 同样的事情,地址应该和 [Route()] 标签一样安全。这是规则。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2015-03-19
    • 2019-08-10
    相关资源
    最近更新 更多