繁体   English   中英

网络核心:“ HttpContext”不包含“当前”的定义

[英]Net Core: 'HttpContext' does not contain a definition for 'Current'`

我正在将一个项目从.Net 4.6.2迁移到.Net Core 2.0。 我在下面收到错误消息。 'HttpContext' does not contain a definition for 'Current'

我该如何解决?

原始代码:

public class CustomerAuthorize : AuthorizeAttribute
{
    /// Gets or sets a session variable indicates that the logged in user has been already authorized to login to the system. 
    private bool IsAuthorized
    {
        get
        {
            if (HttpContext.Current.Session["IsAuthorized"] != null &&

错误代码:

'HttpContext' does not contain a definition for 'Current'

尝试输入的代码:

public class CustomerAuthorize : AuthorizeAttribute
{
    // Gets or sets a session variable indicates that the logged in user has been already authorized to login to the system. 

    const string IsAuthorized2 = "IsAuthorized";
    private bool IsAuthorized
    {
        get
        {
            if (HttpContext.Session.GetString(IsAuthorized2) != null

错误:

非静态字段,方法或属性'HttpContext.Session'需要对象引用

也许您可以使用HttpContext.User.Identity.IsAuthenticated

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM