简体   繁体   English

Azure中的ASP.NET Core 1.1路由

[英]ASP.NET Core 1.1 routing in Azure

App (web api) works fine locally. App(web api)在本地工作正常。 but in azure (App Service) request like http://myapp.azurewebsites.net/api/values returns error 404 (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.) Routing is looking for physical path D:\\home\\site\\wwwroot\\api\\values which doesn't exist. 但在azure(App Service)请求中,如http://myapp.azurewebsites.net/api/values返回错误404(您要查找的资源已被删除,其名称已更改,或暂时不可用。)路由正在寻找对于物理路径D:\\ home \\ site \\ wwwroot \\ api \\ values不存在。

in program.cs: 在program.cs中:

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

        host.Run();

in startup.cs: 在startup.cs中:

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

web.config: 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>

update: 更新: 错误详情

update 2: sub-error code is 0 (sc-substatus). 更新2:子错误代码为0(sc-substatus)。 sc-win32-status is 2 (file not found). sc-win32-status为2(找不到文件)。 I also enabled all logs, viewed them and didn't found any additional tips. 我还启用了所有日志,查看了它们,但没有找到任何其他提示。 Kudu Remote Execution Console didn't show any error and evidence of request at all. Kudu远程执行控制台根本没有显示任何错误和请求证据。 我错了

update 3: short version of api https://drive.google.com/open?id=1TUCImJSmuCC1HJK-x95wg5VOUUEB96wZ 更新3: api的简短版本https://drive.google.com/open?id=1TUCImJSmuCC1HJK-x95wg5VOUUEB96wZ

404 error has a many of sub-status code, to narrow down kindly find the sub-status code, you may review the Failed Request Tracing logs. 404错误有很多子状态代码,要缩小查找子状态代码,可以查看失败请求跟踪日志。

Make sure that the deployment files are available in wwwroot folder. 确保部署文件在wwwroot文件夹中可用。 Place the web.config file under the /site/wwwroot directory. 将web.config文件放在/ site / wwwroot目录下。

By default, on Azure WebApps, all files are stored in the file system with the application, including the media files. 默认情况下,在Azure WebApps上,所有文件都与应用程序一起存储在文件系统中,包括媒体文件。 Refer to the article File structure on azure - https://github.com/projectkudu/kudu/wiki/File-structure-on-azure to know the sets of files & dirs on Azure WebApp. 请参阅文章结构在azure上 - https://github.com/projectkudu/kudu/wiki/File-structure-on-azure以了解Azure WebApp上的文件和目录集。

To enable diagnostics in the Azure portal, go to the page for your web app and click Settings > Diagnostics logs. 要在Azure门户中启用诊断,请转到Web应用程序的页面,然后单击设置>诊断日志。

Further, many startup errors don't produce useful information in the Application Event Log. 此外,许多启动错误不会在应用程序事件日志中生成有用的信息。 You can run the app in the Kudu Remote Execution Console to discover the error: Checkout the steps mentioned in this document: 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 您可以在Kudu远程执行控制台中运行该应用程序以发现错误:查看本文档中提到的步骤: https//docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-应用/解决?视图= aspnetcore-2.0#运行的应用程序内-内式捻控制台

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

I add a custom DateTime Model Binding in Core Web API and it is binding custom DateTime formats in API. 在Core Web API中添加了一个自定义DateTime Model Binding ,它在API中绑定了自定义DateTime格式。 I work well both in local and azure. 我在本地和天蓝色都工作得很好。

You could go this link to check. 你可以去这个链接检查。 And use this link to format datetime. 并使用此链接格式化日期时间。 在此输入图像描述

As @Ajay said, you could enable diagnostics log in azure portal. 正如@Ajay所说,您可以在azure门户中启用诊断日志

Also, you could delete all the files in your KUDU to let the webapp rewrite files into it. 此外,您可以删除KUDU中的所有文件,让webapp将文件重写到其中。

Or when you publish the app, click " Remove additional files at destination " to avoid you have make some changes but it not override. 或者,当您发布应用程序时,单击“ 删除目标位置的其他文件 ”以避免您进行某些更改但不会覆盖。 在此输入图像描述

Project was created in vs2015 and then migrated to vs2017. 项目在vs2015中创建,然后迁移到vs2017。 Obviously not all necessary changes were made in csproj-file. 显然,并非所有必要的更改都在csproj文件中进行。 After rewriting it from the scratch problem was solved. 从头开始重写后,问题就解决了。 I migrated to .net 2.0 also. 我也迁移到了.net 2.0。 Final version of csproj: 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM