简体   繁体   English

Azure 上的 ASP NET Angular 部署提供了 404 找不到任何文件或路由的资源

[英]ASP NET Angular deployment on Azure gives 404 resource not found for any file or route

I've been trying to deploy my ASP.NET Boilerplate project to Azure and so far I've succeeded to publish my project to Azure using Visual Studio publish.我一直在尝试将我的 ASP.NET Boilerplate 项目部署到 Azure,到目前为止我已经成功地使用 Visual Studio 发布将我的项目发布到 Azure。 Right now I have my back-end up and running and I can access the swaggerUI page and execute API calls on my back-end.现在我的后端已经启动并正在运行,我可以访问 swaggerUI 页面并在我的后端执行 API 调用。

Whenever I try to deploy the Angular front-end to the server I only seem to get 404 - Resource not found errors for each file and route I try to access.每当我尝试将 Angular 前端部署到服务器时,我似乎只会收到404 - Resource not found errors我尝试访问的每个文件和路由的404 - Resource not found errors I have been loosely following this guide, the only difference is that I have a merged project, meaning the back-end and front-end are both located on the same Azure appservice.我一直在松散地遵循本指南,唯一的区别是我有一个合并的项目,这意味着后端和前端都位于同一个 Azure 应用程序服务上。

I deploy Angular by first running ng build --prod locally and then moving all the files in my local wwwroot/dist folder to the wwwroot folder of my Azure web app using FTP.我首先在本地运行ng build --prod ,然后使用 FTP 将我本地wwwroot/dist文件夹中的所有文件移动到我的 Azure Web 应用程序的 wwwroot 文件夹来部署 Angular。 I make sure the appsettings.production.json and assets/appconfig.production.json files contain the right URLs and I have added the <mimeMap fileExtension=".json" mimeType="application/json" /> rule to my web.config file.我确保appsettings.production.jsonassets/appconfig.production.json文件包含正确的 URL,并且我已将<mimeMap fileExtension=".json" mimeType="application/json" />规则添加到我的 web.config文件。

Whenever I try to go to either the base url of my site, go to an asset ie /assets/images/login_background.png , or to a specific route, I get a console error that then immediately dissapears.每当我尝试访问我网站的基本 url、资产即/assets/images/login_background.png或特定路线时,我都会收到一个控制台错误,然后立即消失。 Perhaps this has something to do with the routing?也许这与路由有关?

My assets/appconfig.production.json file:我的assets/appconfig.production.json文件:

{
  "remoteServiceBaseUrl": "https://orchestra-agenda.azurewebsites.net/",
  "appBaseUrl": "https://orchestra-agenda.azurewebsites.net/",
  "localeMappings": [
    {
      "from": "pt-BR",
      "to": "pt"
    },
    {
      "from": "zh-CN",
      "to": "zh"
    },
    {
      "from": "he-IL",
      "to": "he"
    }
  ]
}

My appsettings.production.json file in the wwwroot folder:我在 wwwroot 文件夹中的appsettings.production.json文件:

{
  "ConnectionStrings": {
    "Default": "Server=orchestra-agenda.database.windows.net; Database=MyDatabaseName;User ID=MyUserName;Password=MyPassword"
  },
  "App": {
    "ServerRootAddress": "https://orchestra-agenda.azurewebsites.net/",
    "ClientRootAddress": "https://orchestra-agenda.azurewebsites.net/",
    "CorsOrigins": "https://orchestra-agenda.azurewebsites.net/,http://orchestra-agenda.azurewebsites.net/"
  },
  "Authentication": {
    "JwtBearer": {
      "IsEnabled": "true",
      "SecurityKey": "OrchestraAgenda_C421AAEE0D114E9C",
      "Issuer": "OrchestraAgenda",
      "Audience": "OrchestraAgenda"
    }
  }
}

My Web.config :我的Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\OrchestraAgenda.Web.Host.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" startupTimeLimit="3600" requestTimeout="23:00:00" hostingModel="InProcess">
      <environmentVariables>
        <environmentVariable name="COMPLUS_ForceENC" value="1" />
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>
</configuration>
<!--ProjectGuid: 38e184bd-e874-4633-a947-aed4fdb73f40-->

Please let me know if you have any idea what could cause this problem如果您知道可能导致此问题的原因,请告诉我

I figured out what the problem was.我想出了问题所在。 The server expects the web.config file in the /src folder, not in the root folder.服务器需要/src文件夹中的 web.config 文件,而不是根文件夹中。 You also need to add the src/web.config to the assets in the angular.json and add a few rules to the web.config.您还需要将src/web.config添加到angular.jsonassets中,并在 web.config 中添加一些规则。 I solved it after I found this post where they elaborate on it in more detail: angular 2 azure deploy refresh error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable我在找到这篇文章后解决了这个问题,他们更详细地阐述了它: angular 2 azure deploy refresh error : The resource you are looking for has been removed, has changed its name, or is暂时不可用

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

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