【问题标题】:ASP.NET Core 1.1 routing in AzureAzure 中的 ASP.NET Core 1.1 路由
【发布时间】:2018-05-16 13:16:53
【问题描述】:

App (web api) 在本地运行良好。但在像 http://myapp.azurewebsites.net/api/values 这样的天蓝色(应用服务)请求中返回错误 404(您要查找的资源已被删除、名称已更改或暂时不可用。)路由正在寻找物理路径 D:\home\site\ wwwroot\api\values 不存在。

在program.cs中:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseUrls("http://myapp.azurewebsites.net")
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();

在startup.cs中:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddMvcCore(opts =>
         {
              opts.ModelBinderProviders.Insert(0, new CommaDelimitedArrayModelBinderProvider());
          });
    ...
}

web.config:

<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="flase" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

更新:

更新 2: 子错误代码为 0 (sc-substatus)。 sc-win32-status 为 2(未找到文件)。 我还启用了所有日志,查看了它们并没有发现任何额外的提示。 Kudu 远程执行控制台根本没有显示任何错误和请求证据。

更新 3: 短版apihttps://drive.google.com/open?id=1TUCImJSmuCC1HJK-x95wg5VOUUEB96wZ

【问题讨论】:

    标签: c# azure .net-core azure-web-app-service .net-core-1.1


    【解决方案1】:

    404 错误有很多子状态码,要缩小范围请找到子状态码,您可以查看 Failed Request Tracing 日志。

    确保部署文件在 wwwroot 文件夹中可用。将 web.config 文件放在 /site/wwwroot 目录下。

    默认情况下,在 Azure WebApps 上,所有文件都与应用程序一起存储在文件系统中,包括媒体文件。请参阅文章 azure 上的文件结构 - https://github.com/projectkudu/kudu/wiki/File-structure-on-azure 了解 Azure WebApp 上的文件集和目录。

    要在 Azure 门户中启用诊断,请转到 Web 应用的页面,然后单击设置 > 诊断日志。

    此外,许多启动错误不会在应用程序事件日志中产生有用的信息。您可以在 Kudu 远程执行控制台中运行该应用程序来发现错误:查看本文档中提到的步骤:https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.0#run-the-app-in-the-kudu-console

    参考:https://docs.microsoft.com/en-us/azure/app-service/web-sites-enable-diagnostic-log

    【讨论】:

      【解决方案2】:

      我添加了一个custom DateTime Model Binding in Core Web API,它在 API 中绑定了自定义 DateTime 格式。 我在本地和天蓝色工作得很好。

      你可以去这个link检查。并使用此link 格式化日期时间。

      正如@Ajay 所说,您可以在 azure 门户中enable diagnostics log

      另外,您可以删除 KUDU 中的所有文件,让 webapp 将文件重写到其中。

      或者当您发布应用程序时,点击“在目标位置删除其他文件”以避免您进行了一些更改但不会覆盖。

      【讨论】:

      • 日志已启用,选择了错误的处理程序。添加了详细的信息图像。我创建了新的 .net core 2.0(只有 2.0 可用)应用程序,它可以在 azure 中运行。但不是我的 1.1。尝试“删除目标位置的其他文件”。结果是一样的。
      • 嗨@MihailKatrikh,我用.net 1.1 进行测试,没关系。如果可能的话,您能否给我看一下复制的样本,以便更好地解决您的问题。
      • 感谢您的分享~
      【解决方案3】:

      项目是在 vs2015 中创建的,然后迁移到 vs2017。显然,并非所有必要的更改都在 csproj 文件中进行。从头开始重写后,问题就解决了。我也迁移到了 .net 2.0。 csproj 最终版本:

      <Project Sdk="Microsoft.NET.Sdk.Web">
        <PropertyGroup>
          <TargetFramework>netcoreapp2.0</TargetFramework>
          <RootNamespace>ClearIt.Api</RootNamespace>
          <ApplicationIcon />
          <OutputType>Exe</OutputType>
          <StartupObject />
        </PropertyGroup>
        <ItemGroup>
          <ProjectReference Include="..\Dal\Dal.csproj" />
          <ProjectReference Include="..\Models\Models.csproj" />
        </ItemGroup>
        <ItemGroup>
          <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
          <PackageReference Include="AutoMapper" Version="6.0.2" />
          <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="2.0.1" />
          <PackageReference Include="HtmlAgilityPack" Version="1.8.1" />
          <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.0.0" />
          <PackageReference Include="Joonasw.AspNetCore.SecurityHeaders" Version="2.4.0" />
          <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.0" />
          <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
          <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.0" />
          <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.0.0" />
          <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.0.0" />
          <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
          <PackageReference Include="SkiaSharp" Version="1.59.1" />
          <PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
        </ItemGroup>
        <ItemGroup>
          <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
          <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
        </ItemGroup>
        <ItemGroup>
          <None Update="appsettings.Development.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          </None>
          <None Update="appsettings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          </None>
          <None Update="appsettings.Production.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          </None>
          <None Update="Settings.job">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          </None>
          <None Update="web.config">
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
          </None>
        </ItemGroup>
      </Project>
      

      【讨论】:

        猜你喜欢
        • 2017-11-22
        • 2021-01-29
        • 2017-04-13
        • 2020-05-01
        • 2021-09-04
        • 1970-01-01
        • 2016-11-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多