3

うまくいけば、これは簡単です。ユーザー検証用のカスタム テーブルを使用するかなり単純な 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;
}
4

2 に答える 2

2

web.configで設定するのに役立つ場合があります

 <location path="registration.aspx">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>

詳細情報 MSDN リンク http://support.microsoft.com/kb/316871

于 2012-04-23T14:35:44.183 に答える
2

web.config でアクセスを構成できます。これが私がすることの例です:

<location path="register.aspx"> //path here is path to your register.aspx
    <system.web>
        <authorization>
            <allow users="*"/> // this will allow access to everyone to register.aspx
        </authorization>
    </system.web>
</location>
于 2012-04-23T14:37:09.450 に答える