简体   繁体   中英

ASP.NET Core 1.1 routing in Azure

App (web api) works fine locally. 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.

in program.cs:

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

        host.Run();

in 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>

update: 错误详情

update 2: sub-error code is 0 (sc-substatus). sc-win32-status is 2 (file not found). 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. 我错了

update 3: short version of 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.

Make sure that the deployment files are available in wwwroot folder. Place the web.config file under the /site/wwwroot directory.

By default, on Azure WebApps, all files are stored in the file system with the application, including the media files. 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.

To enable diagnostics in the Azure portal, go to the page for your web app and click Settings > Diagnostics logs.

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

Reference: 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. 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.

Also, you could delete all the files in your KUDU to let the webapp rewrite files into it.

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. Obviously not all necessary changes were made in csproj-file. After rewriting it from the scratch problem was solved. I migrated to .net 2.0 also. Final version of 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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