[英]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.