각 aspx 페이지에서 액세스하는 단일 정적 클래스에서 사용자 데이터로드를 처리합니다. 쿠키와 세션을 지원하는 기능을이 프로세스에 추가하고 싶습니다. 그러나 Response.Cookies 객체와 Session 객체는 모두 내 util 클래스에서 사용할 수 없다는 것을 알았습니다.ASP.net에서 어떻게 도우미 클래스의 쿠키와 세션을 사용할 수 있습니까?
기본적으로, 지금은 (그것을 자신의 파일에) 무엇 있습니다
namespace myProject
{
static class myUtil
{
public static myProject.User LoadUser()
{
//Look up user
}
}
}
는 내가하고 싶은 무엇입니까 :
namespace myProject
{
static class myUtil
{
public static myProject.User LoadUser()
{
if (Session['user'] != null)
{ user = Session['user']; }
else if (Response.Cookies['user'] != null)
{ user = Response.Cookies['user']; }
else
{
//Look up user
}
}
}
}
가 어떻게 이런 일이 만들 수 있습니까? 현재 구현에서는 Session 및 Response.Cookies에 대한 모든 참조가 선언되지 않은 객체로 간주됩니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Web.UI.Page;
using System.Web.UI.WebControls;
누군가 downvote에 대한 이유를 설명 할 수 있습니까? – Pankaj