-1

私は C#/.Net の初心者です。管理者をサイトのあるページに誘導し、他のすべてのユーザーを別のページに誘導するログイン ページを作成しようとしています。aspnet_regsql.exe を介して必要なページを正常に追加し、データベースからデータを取得し、ASP.NET 構成バックエンド Web サイトを介してユーザーとフォルダーのアクセス許可を作成できました。ユーザーを作成したときにSQLサーバーデータベースを確認したところ、機能していますが、ログインしようとしても何も起こりません。私はいくつかの調査を行い、このメソッドにコードを追加して正しいページに転送する必要があることに気付きましたが、どこから始めればよいかわかりません。

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)

{

編集:リダイレクトに関するご意見ありがとうございます。データベースでのログインをどのように検証しますか? ログイン コントロールに対応する標準テーブルを使用しています。

4

4 に答える 4

2

Response.Redirect() は途中で役立つはずです

于 2013-06-21T14:40:38.780 に答える
2

メンバーシップ プロバイダーを使用していると仮定します。

if (Membership.GetUser() != null && Page.User.IsInRole("administrator"))
{
   //admin user
   Response.Redirect("adminarea.html");
}
于 2013-06-21T14:43:13.257 に答える
2

First of all you must authenticate the user and then you redirect user to page that's available for him.

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") 
} 

If you use a custom data table, then you can write a procedure to authenticate the user, I use a custom data table to hold members and I validate using an SQL procedure, as shown below:

 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
于 2013-06-21T15:01:18.923 に答える
1

置く

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)

{

// Validate From DB
//After successful Validation

Response.Redirect("Your Page name");

}
于 2013-06-21T14:42:12.983 に答える