[英]Deploying Blazor app to Azure using AAD Authentication
I've created a default Blazor App (Server-side) in Visual Studio 2019 with Azure AD authentication.我已经在 Visual Studio 2019 中使用 Azure AD 身份验证创建了一个默认的 Blazor 应用程序(服务器端)。 Running the app locally it authenticates against AAD as expected.
在本地运行应用程序,它按预期对 AAD 进行身份验证。 However, when deployed to an App Service in Azure the app won't run.
但是,当部署到 Azure 中的应用服务时,该应用将不会运行。 The deployment process works fine, Deployment Mode is Self-Contained and App Service is Windows (Linux works the same way).
部署过程工作正常,部署模式是自包含的,应用服务是 Windows(Linux 的工作方式相同)。 All files and settings are made appropriately, but the below error is displayed when navigating to the site.
所有文件和设置都已正确进行,但导航到该站点时会显示以下错误。
This page isn't working blazorappxxxxxxx.azurewebsites.net is currently unable to handle this request.此页面不工作 blazorappxxxxxxx.azurewebsites.net 当前无法处理此请求。
HTTP ERROR 500 HTTP 错误 500
Disable the authentication code in startup.cs and redeploy, now the app works.禁用 startup.cs 中的身份验证代码并重新部署,现在应用程序可以运行了。
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
The App is registered in AAD and Redirect URIs are set, implicit grant is configured for Access Token and ID Token.应用在 AAD 中注册并设置了重定向 URI,为 Access Token 和 ID Token 配置了隐式授权。
Try to use the code as below:尝试使用如下代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddControllers();
}
Behind the scenes, Visual Studio automatically registers our ASP.NET Core app in Azure AD App Registration.在幕后,Visual Studio 会在 Azure AD 应用注册中自动注册我们的 ASP.NET Core 应用。 For more details, you could refer to this tutorial .
更多细节,你可以参考这个教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.