Can I access session state from an HTTPModule?에있는 솔루션 다음에 IHttpModule에서 세션 상태에 액세스 할 수 있습니다. 일부 파일에 대한 액세스를 제어하는 데이 파일을 사용하고 있기 때문에 누군가 액세스 권한이없는 경우 로그인 페이지로 리디렉션하려고합니다. HttpContext.Current.Response.Redirect (페이지); 웹 서버를 잠급니다. 그래서 내 게시물 획득 요청 상태 함수는 다음과 같습니다 ...IHttpModule에서 세션에 액세스하여 response.redirect를 수행 할 수 있습니다.
void Application_PostAcquireRequestState(object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler;
if (resourceHttpHandler != null)
{
// set the original handler back
HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
}
HttpContext context = HttpContext.Current;
string filePath = context.Request.FilePath;
context.Trace.Write("HttpDownloadModule", "File path: " + filePath);
Boolean hasAccess = true;
if (filePath.Contains("content/downloads"))
{
//check to make sure a session has been established already....
if (context.Session == null)
hasAccess = false;
SecurityBLL security = new SecurityBLL();
string fileName = filePath.Split('/').Last();
//check to see if a user is logged in
if (!CitrixAccess.loggedin)
hasAccess = false;
//check access for download
if (!security.checkSecurityByDownload(fileName))
hasAccess = false;
if (!hasAccess)
{
HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
HttpContext.Current.Response.Redirect("../../login.aspx");
}
}
}
어떤 생각? 도와 주셔서 감사합니다!