2013-06-18 128 views
1

您好,禁用/帳號/在用戶登錄後註冊頁面 - ASP.net

我在尋找解決方案以禁用打開鏈接/帳號/註冊,在用戶登錄後。我對asp.net應用程序的瞭解還很少,需要鍛鍊。

鏈接在主頁面被禁用,但是當我手動輸入鏈接到地址欄時,如:http://example.com:23456/Account/Register我使用登錄用戶獲得實際註冊。

我需要做的是在加載註冊頁面和重定向到主頁之前檢查是否有登錄用戶。

對於很多問題我已經回答了這個論壇,但現在我需要幫助..

預先感謝您:)

回答

1

在你Page_Load事件時,可以檢查,如果用戶登錄,如果他重定向所以:

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (HttpContext.User.Identity.IsAuthenticated) 
    { 
     Response.Redirect("~/Default.aspx"); //redirect to main page 
    } 
} 

注意這是ASP.NET的解決方案。而MVC變種:

public ActionResult Register() 
{ 
    if (!HttpContext.User.Identity.IsAuthenticated) 
    { 
     return View(); 
    } 
    else 
    { 
     return RedirectToAction("Index"); 
    } 
} 
+0

我使用WebMatrix的作爲完全以新手,並且是正確的,我把這個代碼... – user2497254

+0

@ { if(HttpContext.Current.User.Identity.IsAuthenticated) { Response.Redirect(「〜/」); //重定向到主頁 } } – user2497254

+0

感謝您的快速解決方案! – user2497254

0

於是否已經註冊的申請,如果他是不是重定向他的主頁登記檢查的Page_Load事件。你應該寫這樣的東西。

protected void Page_Load(object sender, EventArgs e) 
     { 

if (!IsPostBack) 
{ 
if (MySessionHelper.UserInfo != null) 
      { 
       Response.Redirect("http://example.com:23456/", false); 
      } 
} 
} 

這裏保存記錄的MySessionHelper.UserInfo會話對象/註冊用戶信息