我一直在尝试将ASP.NET Boilerplate项目部署到Azure,到目前为止,我已经成功使用Visual Studio publish将项目发布到Azure。现在,我已经启动并运行了后端,并且可以访问swaggerUI页面并在后端上执行API调用。
每当我尝试将Angular前端部署到服务器时,我似乎只为尝试访问的每个文件和路由获得404 - Resource not found errors
。我一直在随意跟踪this guide,,唯一的不同是我有一个合并的项目,这意味着后端和前端都位于同一Azure应用程序服务上。
我首先通过在本地运行ng build --prod
,然后使用FTP将本地wwwroot/dist
文件夹中的所有文件移动到Azure Web应用程序的wwwroot文件夹中来部署Angular。我确保appsettings.production.json
和assets/appconfig.production.json
文件包含正确的URL,并且已将<mimeMap fileExtension=".json" mimeType="application/json" />
规则添加到我的web.config文件中。
每当我尝试转到网站的基本URL,转到资产/assets/images/login_background.png
或特定路径时,都会收到控制台错误,然后立即消失。也许这与路由有关?
我的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"
}
]
}
我的appsettings.production.json
文件在wwwroot文件夹中:
{
"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"
}
}
}
我的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-->
请让我知道您是否会导致此问题的原因
答案 0 :(得分:0)
我弄清楚了问题所在。服务器期望web.config文件位于/src
文件夹中,而不是根文件夹中。您还需要将src/web.config
添加到assets
中的angular.json
并向web.config添加一些规则。找到这篇文章后,我对其进行了详细说明,从而解决了问题:angular 2 azure deploy refresh error : The resource you are looking for has been removed, had its name changed, or is temporarily unavailable