在Azure上部署ASP.NET Angular时,对于任何文件或路由,都会出现404资源未找到的错误。
在Azure上部署ASP.NET Angular时,对于任何文件或路由,都会出现404资源未找到的错误。
我一直在尝试将我的ASP.NET Boilerplate项目部署到Azure,到目前为止,我已经成功使用Visual Studio发布将我的项目发布到Azure。现在我的后端已经运行起来了,我可以访问swaggerUI页面并在后端执行API调用。
每当我尝试将Angular前端部署到服务器时,我似乎只会得到404 - 资源未找到的错误,无论是对于每个文件还是每个路由。我大致按照这个指南(链接已省略)进行操作,唯一的区别是我有一个合并的项目,意味着后端和前端都位于同一个Azure应用服务上。
我先在本地运行"ng build --prod"来部署Angular,然后使用FTP将本地"wwwroot/dist"文件夹中的所有文件移动到Azure Web应用的"wwwroot"文件夹中。我确保"appsettings.production.json"和"assets/appconfig.production.json"文件中包含正确的URL,并在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"
}
]
}
我的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"
}
}
}
我的"Web.config"文件:
如果你有任何关于可能导致这个问题的想法,请告诉我。
问题原因:服务器期望在/src文件夹中找到web.config文件,而不是在根文件夹中。还需要将src/web.config添加到angular.json中的assets,并在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