C# 净核心:';HttpContext';不包含';当前'`

C# 净核心:';HttpContext';不包含';当前'`,c#,.net-core,asp.net-core-mvc,.net-core-2.0,C#,.net Core,Asp.net Core Mvc,.net Core 2.0,我正在将一个项目从.Net 4.6.2迁移到.Net Core 2.0。 我收到下面的错误“HttpContext”不包含“当前”的定义。 我将如何解决这个问题 原始代码: public class CustomerAuthorize : AuthorizeAttribute { /// Gets or sets a session variable indicates that the logged in user has been already authorized to logi

我正在将一个项目从.Net 4.6.2迁移到.Net Core 2.0。 我收到下面的错误<代码>“HttpContext”不包含“当前”的定义。

我将如何解决这个问题

原始代码:

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
错误代码:

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
尝试的代码:

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
错误:

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

的可能重复项也请参见:。这里有一个很好的答案:的可能重复项可能要查看SessionStorage objecthmm,这不起作用,还有别的解决办法吗?@JohnThomas你需要发表你自己的问题,而不是在一个有公认答案的问题上加上悬赏。显然,被接受的答案对OP有效,除非你发布为什么这对你无效,否则你不会在这里得到更多/不同的答案。