作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是网络应用程序的新手。我创建了一个自定义原则并尝试在 CurrentDomain 中设置它。此代码在 WPF 应用程序中完美运行。但这里抛出策略异常“默认主体对象不能设置两次。”
var principal = new CustomPrinciple(currentIdentity);
Thread.CurrentPrincipal = principal;
AppDomain.CurrentDomain.SetThreadPrincipal(Thread.CurrentPrincipal);
我的 CustomPrincple 派生自 ClaimsPrinciple
public class CustomPrinciple : ClaimsPrincipal
{ }
我想知道为什么不允许我在这里设置它。如何在 Web 应用程序中设置自定义原则。
最佳答案
自定义主体应该在 global.asax 文件中为发出的请求设置,而不是线程。然后你从 HttpContext.User Property 中获取自定义主体
这个问题的答案详细说明了最好的方法:ASP.NET MVC - Set custom IIdentity or IPrincipal
关于c# - 如何在 asp.net 中设置自定义主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062608/
我是一名优秀的程序员,十分优秀!