2013-06-21 126 views
-1

我是C#/ .Net的新手。我正在嘗試創建一個登錄頁面,將管理員指向網站的一個頁面,將所有其他用戶指向另一個頁面。我通過aspnet_regsql.exe成功添加了所需的頁面,能夠從數據庫獲取數據,並通過ASP.NET配置後端網站創建用戶和文件夾權限。當我讓用戶檢查了SQL服務器數據庫並且它正在工作,但是當我嘗試登錄時沒有任何反應。我做了一些研究,並意識到我需要向此方法添加代碼以使其轉到正確的頁面,但我不知道從哪裏開始。登錄後將用戶重定向到新頁面

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) 

{ 

編輯: 感謝您的重定向輸入。你如何驗證數據庫的登錄?我正在使用與登錄控制一起使用的標準表。

+0

這裏有這麼多問題,我不知道從哪裏開始... –

回答

2

首先,您必須驗證用戶,然後將用戶重定向到可供他使用的頁面。

If (authentication success) 
{ 
// iF you want to parse user id of the user to the page then you can use query string 
// like this " ~/home.page?id=129" 

Response.Redirect("~/Home.page") 
} 

如果使用自定義數據表,那麼你可以寫一個程序對用戶進行認證, 我使用自定義數據表來保存成員和我驗證使用SQL過程中,如下圖所示:

Create Procedure [dbo].[Authenticate] 
    (
    @Email varchar(50), 
    @Password varchar(50)  
    ) 
    As 

    Declare @@ID int 


    Set @@ID = (select ID from users where Email = @Email) 

    if exists (select * from [dbo].[Users] where Email = @Email and [Password] = @Password) 
    select 'True' as IsValid , @@ID as ID 
    else 
    select 'False' as Isvalid , 0 as ID 

    return 
2

的Response.Redirect()可以幫助你對你的方式

1

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) 

{ 

// Validate From DB 
//After successful Validation 

Response.Redirect("Your Page name"); 

} 
+0

感謝您對重定向的輸入。你如何驗證數據庫的登錄?我正在使用與登錄控制一起使用的標準表。 –

2

假設你正在使用的成員資格提供:

if (Membership.GetUser() != null && Page.User.IsInRole("administrator")) 
{ 
    //admin user 
    Response.Redirect("adminarea.html"); 
} 
相關問題