首页 > 解决方案 > 在asp net framework 4.5中使用多种身份验证方法

问题描述

我需要在我们现有的 ASP.NET MVC 网站项目中添加 Azure 活动目录身份验证,但我需要保留表单身份验证方法。

我完成了本教程中的所有步骤: https ://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp

但由于某种原因没有重定向到 AD 登录页面,正在寻找解决方案,请参阅:IAuthenticationManager.Challenge not calling ExternalLoginCallback

将身份验证模式设置为无并添加标签可以解决重定向问题,但删除之前的表单身份验证。

有没有办法在同一个项目中使用表单身份验证和 Azure AD?

标签: c#asp.netasp.net-mvcazure-active-directory

解决方案


  • 使用个人用户帐户创建一个新应用程序。

  • 安装这个包:Microsoft.AspNetCore.Authentication.AzureAD.UI

  • services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); `services.AddDefaultIdentity() .AddEntityFrameworkStores(); services.AddAuthentication(sharedOptions => }).AddAzureAD(options => Configuration.Bind("AzureAd", options)).AddCookie();

  • 更新 appsettings.json "AzureAd": { "Instance": "https://login.microsoftonline.com/",

  • “域”:“xxx.onmicrosoft.com”,“租户 ID”:“xxxxxx-xxxxx-4f08-b544-b1eb456f228d”,

  • “ClientId”:“xxxxx-xxxxx-4717-9821-e4f718fbece4”,“CallbackPath”:“/signin-oidc”,

    "CookieSchemeName": "Identity.External" },

阅读更多关于这里。& 用于 Azure AD身份验证


推荐阅读