简体   繁体   English

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

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

I am migrating a project from .Net 4.6.2 into .Net Core 2.0. 我正在将一个项目从.Net 4.6.2迁移到.Net Core 2.0。 I am receiving error below. 我在下面收到错误消息。 'HttpContext' does not contain a definition for 'Current'

How would I resolve this? 我该如何解决?

Original Code: 原始代码:

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 &&

Error Code: 错误代码:

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

Attempted Code: 尝试输入的代码:

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

Error: 错误:

An object reference is required for the non-static field, method, or property 'HttpContext.Session' 非静态字段,方法或属性'HttpContext.Session'需要对象引用

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

暂无
暂无

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

相关问题 HttpContext不包含Current的定义 - HttpContext doess not contain definition for Current 我使用“HttpContext.Current”,但调试时出现错误“HttpContext”不包含“Current”的定义 - I use “HttpContext.Current” but debug got error “HttpContext' does not contain a definition for 'Current” “IApplicationBuilder”不包含“HttpContext”的定义 - 'IApplicationBuilder' does not contain a definition for 'HttpContext' Delegate在.net核心中不包含CreateDelegate的定义 - Delegate does not contain a definition for CreateDelegate in .net core HttpContext.GetOwinContext() 不包含 GetOwinContext() 的定义吗? - HttpContext.GetOwinContext() does not contain definition for GetOwinContext()? c# 'HttpContext' 不包含 'Current' 的定义,无法读取我的 Web 应用程序上发布的值 - c# 'HttpContext' does not contain a definition for 'Current', Could not read posted values on my web application http请求在.net core 2.1中不包含createresponse的定义 - http request does not contain a definition for createresponse in .net core 2.1 ASP.NET Core:IConfigurationBuilder 不包含 AddAzureKeyVault 的定义 - ASP.NET Core: IConfigurationBuilder Does Not Contain Definition For AddAzureKeyVault .net core 3.1 Blazor WebAssembly:不包含“LoginMode”的定义 - .net core 3.1 Blazor WebAssembly: does not contain a definition for "LoginMode" .NET Core Xunit - IActionResult' 不包含 'StatusCode' 的定义 - .NET Core Xunit - IActionResult' does not contain a definition for 'StatusCode'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM