代码之家  ›  专栏  ›  技术社区  ›  pg0xC

在IISExpress中设置基本路径,在ASP中设置webapi。净5

  •  0
  • pg0xC  · 技术社区  · 9 年前

    我需要让WebAPI项目在不同的基本路径下工作。我在VisualStudio下创建了一个使用WebAPI和ASP的简单项目。NET 5。

    底部路径设置为 http://localhost:38170/ 我的项目运行良好,我能够从测试控制器获取值( http://localhost:38170/api/values ). 在此阶段,我的IIS Express配置是:

    <site name="WebApi" id="2">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
       </application>
       <bindings>
            <binding protocol="http" bindingInformation="*:38170:localhost" />
       </bindings>
    </site>
    

    我尝试更改项目属性下的应用程序URL以反映我的需求: http://localhost:38170/xxx

    现在正在运行项目并命中 http://localhost:38170/xxx/api/values 结果为404。正在尝试 http://localhost:38170/api/values 从控制器返回值,就像没有任何变化一样。我注意到VisualStudio中的更改没有以任何方式反映在IIS Express配置中(我不知道它们是否应该…)。

    我尝试手动更改IISExpress上的路径,如以下线程所示: Creating virtual directories in IIS express .

    <site name="WebApi" id="2">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/xxx" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
       </application>
       <bindings>
            <binding protocol="http" bindingInformation="*:38170:localhost" />
       </bindings>
    </site>
    

    结果是:

    http://localhost:38170/api/values -500.19错误(配置错误),这还可以-我不打算这样做

    http://localhost:38170/xxx/api/values -502.3-点击httpPlatformHandler时网关错误

    我想这个错误是在httpPlatformHandler配置中的某个地方,但我不确定如何结合IIS Express来实现。我的网络。配置为:

    <configuration>
      <system.webServer>
        <handlers>
          <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
        </handlers>
        <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
      </system.webServer>
    </configuration>
    

    我尝试了随机更改,如更改路径属性 xxx/* 但什么都不管用。

    编辑: 澄清问题。

    如何在ASP。NET 5(ASP.NET Core)在IISExpress上使用httpPlatformHandler和Kestrel设置根以外的基本路径。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Lex Li    9 年前

    您破坏了文件,因为您的修改违反了IIS Express配置规则。

    我建议您使用智能工具(如JexusManager)来操作它,然后您可以将VisualStudio项目与正确的URL同步。

    例如,404是预期的,因为您的应用程序标签的路径设置为/,所以没有应用程序或虚拟目录可以为xxx服务。

    500.19以后的版本也是应该的,因为在添加名为xxx的有效虚拟目录时,您删除了根虚拟目录。这是完全错误的,因为必须存在根虚拟目录。