丢失的安全性要求不同控制器中的身份

时间:2018-07-19 06:29:28

标签: c# authentication claims-based-identity

我正在研究WebAPI 2项目。我正在使用安全性声明身份进行身份验证。当我访问HomeController时,存在HttpContext.Current.User.Identity。但是当我重定向到另一个Controller时,HttpContext.Current.User.Identity为null。

Controller code - 
 [RequirePermenantEmployee]
    public class EstimationController : BaseApiController
    {
}    

Autherization code -
public class RequirePermenantEmployee : AuthorizeAttribute
    {
if (HttpContext.Current.User == null || HttpContext.Current.User.Identity == null ||
                HttpContext.Current.User.Identity.IsAuthenticated == false)
            {}
}

上面是示例授权代码。 HttpContext.Current.User.Identity仅在HomeController中可用。它不适用于其他控制器。您能告诉我如何解决此问题吗?

1 个答案:

答案 0 :(得分:0)

最后,我找出了根本原因。我只是评论了WebAPIconfig文件中的以下代码,它开始起作用

<div className="col-md-3">
<select name="borrowerState" className="form-control dropDownStyle" onChange={this.handleChange} value={this.props.borrower.borrowerState}>
    {this.populateOptions()}
</select>