Visual Studio2008を起動して、新しいサイトを作成

.NET Framework2.0を選択して、

デフォルトページ以外にも、2つのページを作成。

まずは、ログイン画面。

同じ要領で、ユーザページ(ログイン後の画面)を作成する。

続いてカスタムメンバシッププロバイダを作成する。

ここで「はい」を選択し、App_Codeに入れる。

クラスの継承元[:MembershipProvider]を入力し、

そのキーワード(MemberhsipProvier)の上で右クリック、
継承クラスの実装を選択して、

abstractのメソッドを実装するスケルトンを作成。
そのあと、直近で利用するValidateUser()のみをちょっと
実装する。

続いてWeb.configの変更。元のWeb.configからの変更箇所は、
authenticationタグ(変更) 、membershipタグ(追加)、
authorizationタグ(追加)、 下のlocationタグ(追加)
です。

ログイン画面、ログインパーツを置いてみます。

置いたログインパーツをクリックしてコード編集画面へ、

コード編集画面で、ログイン部分を記述

ログインパーツで入力されたもので認証を呼び出す。

これでコード修正おわり。
あとはF5で実行。

OKを選択し、動作確認。
Default.aspxは未ログインでも表示できること、
UserPage.aspxを未ログイン状態で表示するとログインページ
に移動し、ログイン入力すると、UserPage.aspxを表示すること、
ログイン後は、UserPage.aspxを直接入力しても表示されることを確認する。
0 件のコメント:
コメントを投稿