0
對不起,這可能是高級VB.NET程序員的基本問題,但我是VB.NET的初學者,所以我需要您的建議。IHttpHandler中的上下文問題
我有一個Web應用程序,登錄是一些特定頁面所必需的。要檢查如果用戶登錄,老程序員使用這種技術:
Dim sv As New WL.SessionVariables(Me.Context)
If Not (sv.IsLoggedIn) Then
Response.Redirect(WL.SiteMap.GetLoginURL())
End If
好吧,我不得不使用這個記錄在由我做了處理程序檢查,我想這:
Public Class CustomHandler
Implements System.Web.IHttpHandler, IReadOnlySessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim sv As New WL.SessionVariables(context)
If Not (sv.IsLoggedIn) Then
context.Response.Write("No access unless you're the CEO!!!" & sv.IsLoggedIn)
ElseIf sv.IsLoggedIn Then
DownloadFile(context)
Else
End If
End Sub
//other code
End Class
那麼,「登錄」檢查總是假的(即使我登錄後)和我認爲這是一個問題與上下文。因此,所有其他頁面都可以正常使用日誌檢查功能,但此處理程序有此特定問題。
你們能幫忙嗎?
UPDATE:
登錄的完成槽這種方法:
Public Sub SetCreditialCookie(ByVal accountID As Integer)
Me.AccountID = accountID
m_context.Session.Item("loggedInAccount") = accountID
m_context.Response.Cookies.Add(New System.Web.HttpCookie("account_id", CStr(m_context.Session.Item("account_id"))))
m_context.Response.Cookies("account_id").Expires = DateTime.Now.AddDays(5)
End Sub
,並檢查它的登錄,這種方法被稱爲:
Public Function IsLoggedIn() As Boolean
If Not m_context.Session.Item("loggedInAccount") Is Nothing And Me.AccountID = m_context.Session.Item("loggedInAccount") Then
Return True
Else
Return False
End If
End Function
UPDATE 2: - 調試代碼顯示有多個ki nd登錄,我在會話中檢查錯誤的。
謝謝jdavies。我已經更新了我的問題與登錄的代碼。如你所說,你是否看到任何可能導致衝突的錯誤? –
什麼時候調用SetCreditialCookie? – jdavies
Wehn按下登錄按鈕:'sv.SetCreditialCookie(accountID)' –