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