c# - 在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?
解决方案
使用个人用户帐户创建一个新应用程序。
安装这个包: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" },
推荐阅读
- java - Java中Web应用程序中的后台进程
- .net-core - 永远不会触发 DataLoading 事件
- angular - 使用 Angular 7 保持屏幕和数据状态
- c# - 无法在 UWP 中使用 FromFile 中的路径加载图像
- mysql - 如何导出从 mysql 查询返回的“结果”?
- oracle - Oracle UTL_FILE 读取 CSV 文件行
- database - 在具有简单桌面 c# 应用程序的单台机器上运行时,如何管理(init\start\restart\create schema)我的 postgreSQL 服务器?
- wordpress - 如何在不影响主题或网站其他部分的情况下将自定义 HTML 文件插入 WordPress
- c++ - 异常后重置 Cuda 上下文
- javafx - 如何从子控制器为父控制器中的元素设置 FXML 属性