我正在将一个项目从.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'需要对象引用
答案 0 :(得分:1)
也许您可以使用HttpContext.User.Identity.IsAuthenticated