- ASP.NET Web API Security Essentials
- Rajesh Gunasundaram
- 64字
- 2021-07-30 10:15:54
Setting the principal
If the application has the custom authentication logic implemented, then we must set the principal in two places:
Thread.CurrentPrincipal
is the standard way to set the thread's principal in .NET.HttpContext.Current.User
is specific to ASP.NET.
The following code shows setting up the principal:
private void SetPrincipal(IPrincipal principal) { Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) { HttpContext.Current.User = principal; } }
推薦閱讀
- Java應(yīng)用與實戰(zhàn)
- Apache Spark 2 for Beginners
- 編程珠璣(續(xù))
- JavaScript前端開發(fā)與實例教程(微課視頻版)
- PHP+MySQL網(wǎng)站開發(fā)項目式教程
- Functional Kotlin
- Web程序設(shè)計(第二版)
- 全棧自動化測試實戰(zhàn):基于TestNG、HttpClient、Selenium和Appium
- Selenium Testing Tools Cookbook(Second Edition)
- Web性能實戰(zhàn)
- Julia數(shù)據(jù)科學(xué)應(yīng)用
- Monitoring Docker
- Java EE 7 Development with WildFly
- VMware vSphere Design Essentials
- 人件集:人性化的軟件開發(fā)