簡體   English   中英

從ASP經典登錄頁面將用戶重定向到相應的頁面

[英]Redirect user to the appropriate page from ASP classic login page

我有一個網站,其中使用vbscript編寫的登錄頁面來保護某些頁面(框架是asp經典)。 鑒於用戶名為“foo”且密碼為“bar”,登錄頁面當前接受用戶名和密碼,然后將用戶重定向到默認頁面。 我們稱之為“page1”。 以下是代碼:

Response.Buffer = True
If lcase(Request.Form("username")) = "foo" AND lcase(Request.Form("password")) = "bar" then
Session.Contents("foo") = "1"
Response.Redirect("page1.asp")
Else
Response.Redirect("failure.asp")
End If

這樣可行但用戶將始終被重定向到同一頁面,無論他們嘗試訪問哪個頁面。 我希望用戶在被發送到登錄頁面之前被重定向到他們嘗試訪問的頁面。 假設用戶想要轉到“page2”,我嘗試了以下代碼:

Response.Buffer = True
If Request.ServerVariables("URL")= "http://www.mysite.com.com/page2.asp" AND lcase(Request.Form("username")) = "foo" AND lcase(Request.Form("password")) = "bar" then
Session.Contents("Dealer") = "1"
Response.Redirect("page2.asp")
ElseIf lcase(Request.Form("username")) = "foo" AND lcase(Request.Form("password")) = "bar" then
Session.Contents("foo") = "1"
Response.Redirect("page1.asp")
Else
Response.Redirect("failure.asp")
End If

這不起作用,這可能是因為

Request.ServerVariables("URL")

正在從登錄頁面中提取網址。 有誰知道如何將用戶發送到最初請求的頁面?

在此先感謝您的任何幫助/建議!

在您的登錄表單頁面上為引用頁面添加一個隱藏字段,並填充值如下:

<input name="referer" type="hidden" value="<%= Request.ServerVariables("HTTP_REFERER") %> />

成功提交表單后重定向到此頁面:

Response.Redirect(Request.Form("referer"))

我不知道“經典asp”,也不知道VB腳本。

但是在查詢字符串中添加所需頁面(需要登錄)的方法呢?

強制登陸用戶登錄login.aspx?redirectUrl = desiredPage.asp

登錄完成后,通過從查詢字符串中檢索頁面重定向到頁面?

這個頁面更好地解釋了它。

ASP.NET:指導用戶登錄頁面,登錄后發送用戶回到原來請求的頁面?

每個安全頁面都應該有一些標題代碼,如下所示:

If Not Session("LoggedIn") Then
    Response.Redirect "login.asp?r=" & Server.UrlEncode(Request.ServerVariables("SCRIPT_NAME"))
End If

我通常將其放入名為“private.asp”的包含文件中,並確保將其包含在應保護的每個頁面的頂部。

在您的登錄頁面中,在您成功登錄用戶后,檢查您的查詢字符串值以查看是否應將用戶轉發回最初請求的頁面:

' After successful login...
strReturnURL = Request.QueryString("r")

If Len(strReturnURL) > 0 Then
    Response.Redirect strReturnURL
Else
    ' Send them to your homepage...
    Response.Redirect "/"
End If

您的登錄頁面網址應如下所示:

http://domain.com/login.asp?urlstr=page2.asp

Response.Buffer = True
dim redirecturl
 redirecturl = Request("urlstr")
If  lcase(Request.Form("username")) = "foo" AND lcase(Request.Form("password")) = "bar"  and len(redirecturl)>0 then
Session("Dealer") = "1"
Response.Redirect(redirecturl)
ElseIf lcase(Request.Form("username")) = "foo" AND lcase(Request.Form("password")) = "bar" and len(redirecturl)=0  then
Session("foo") = "1"
Response.Redirect("login.asp")
Else
Response.Redirect("failure.asp")
End If

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM