うまくいけば、これは簡単です。ユーザー検証用のカスタム テーブルを使用するかなり単純な ASP.NET (フレームワーク バージョン 2) アプリがあります。とにかく、ログインと登録の 2 つのページがあります。目的は何なのか推測できます。ユーザーは、登録リンクをクリックして登録を要求できるはずです。これは、ユーザーが存在するかどうかなどを確認するためにいくつかのデータベース呼び出しを行う送信ボタンのあるフォームです。ログイン ページでは、確認のために認証 Cookie を使用します。私はフォーム認証を使用しています - これは私の web.config にあります:
<authentication mode="Forms">
<forms loginUrl="logon.aspx" name="adAuthCookie" timeout="30" path="/" defaultUrl="~/logon.aspx">
</forms>
</authentication>
登録ページへの http 呼び出しを行うたびに (つまり、http://localhost/registration.aspxと入力すると、ログイン ページにリダイレクトされます。
global.asax.cs ファイルにはこれが含まれています - これは認証チェックです。ユーザーがこのページにアクセスするために認証される必要がないため、要求元のページが登録ページである場合、このチェックを無効にします。これを行う方法はありますか?
void Application_AuthenticateRequest(object sender, EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie)
{
//There is no authentication cookie.
return; // right here it will return null then redirect to login.aspx
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (Exception ex)
{
//Write the exception to the Event Log.
return;
}
if (null == authTicket)
{
//Cookie failed to decrypt.
return;
}
//When the ticket was created, the UserData property was assigned a
//pipe-delimited string of group names.
string[] groups = authTicket.UserData.Split(new char[] { '|' });
//Create an Identity.
GenericIdentity id = new GenericIdentity(authTicket.Name, "LdapAuthentication");
//This principal flows throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, groups);
Context.User = principal;
}