找回密碼
 註冊
搜索
查看: 6097|回復: 1

ASP.NET Login Control 登入後 Redirect 的方法

[複製鏈接]
發表於 2010-12-14 10:46:40 | 顯示全部樓層 |閱讀模式
<asp:login id="LoginUser" runat="server" onauthenticate="OnAuthenticate"
    onloggedin="OnLoggedIn" onloggingin="OnLoggingIn" destinationpageurl="~">
</asp:login>

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
   e.Authenticated = false; //認證失敗
    if (String.Compare(ctlLogin.UserName, "foo", true) == 0 &&
        String.Compare(ctlLogin.Password, "bar", false) == 0)
    {
        e.Authenticated = true; //認證成功,則會自動執行OnLoggedIn Function,進行Redirect
    }
}       

protected void OnLoggedIn(object sender, EventArgs e)
{
    '覆蓋 ReturnUrl頁面參數
    Response.Redirect("~"); // 或是 Response.Redirect(Login1.DestinationPageUrl)
}


Login事件說明:
LoggedIn         發生於使用者登入網站且已經過驗證時。
LoggingIn         發生於使用者送出登入資訊之後,進行驗證之前。

Reference:
http://netomatix.com/Development/LoginControlBasic.aspx
http://zh-tw.w3support.net/index.php?db=so&id=33166
http://www.sharepointdev.net/sha ... irectly-18817.shtml
 樓主| 發表於 2010-12-14 14:07:45 | 顯示全部樓層

SetAuthCookie + RedirectFromLoginPage 用法

if (Request.QueryString["ReturnUrl"] != null)
    {
        FormsAuthentication.RedirectFromLoginPage("someuserid", false);
    }
    else
    {
        FormsAuthentication.SetAuthCookie("someuserid", false);
        Response.Redirect("~/SomePage.aspx");
    }

Reference: http://stackoverflow.com/questio ... with-windows-safari
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-3-29 05:05 , Processed in 0.017359 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表