ASP.NET アプリケーションの承認アクセス許可を制御する

この更新プログラムでは、タグを Web.config ファイルに適用<location>して、特定のファイルとフォルダーへのアクセスを構成する方法について説明します。

元の製品バージョン: ASP.NET
元の KB 番号: 316871

概要

このステップ バイ ステップ ガイドを使用して、タグを <location>Web.config ファイルに適用して、特定のファイルとフォルダーへのアクセスを構成します。

ASP.NET アプリケーションでフォーム ベースの認証を使用する場合、認証されたユーザーのみがアプリケーション内のページへのアクセス権を付与されます。 認証されていないユーザーは、資格情報を送信できる Web.config ファイルの属性でloginUrl指定されたページに自動的にリダイレクトされます。 場合によっては、認証を必要とせずに、アプリケーション内の特定のページへのアクセスをユーザーに許可することができます。

特定のファイルとフォルダーへのアクセスを構成する

  1. フォーム ベースの認証を設定します。 詳細については、「 C# .NET を使用して ASP.NET アプリケーションで Forms-Based 認証を実装する方法」を参照してください。

  2. アプリケーション内の任意のページが自動的に Logon.aspx にリダイレクトされるように要求します。

  3. Web.config ファイルに、次のコードを入力するか貼り付けます。

    このコードは、すべてのユーザーに Default1.aspx ページと Subdir1 フォルダーへのアクセスを許可します。

    <configuration>
        <system.web>
            <authentication mode="Forms" >
                <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
                </forms>
            </authentication>
            <!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->
            <authorization>
                <deny users="?" />
            </authorization>
        </system.web>
        <!-- This section gives the unauthenticated user access to the Default1.aspx page only. It is located in the same folder as this configuration file. -->
        <location path="default1.aspx">
            <system.web>
                <authorization>
                    <allow users ="*" />
                </authorization>
            </system.web>
        </location>
        <!-- This section gives the unauthenticated user access to all of the files that are stored in the Subdir1 folder. -->
        <location path="subdir1">
            <system.web>
                <authorization>
                    <allow users ="*" />
                </authorization>
            </system.web>
        </location>
    </configuration>
    

    ユーザーは、 Default1.aspx ファイル、またはアプリケーション内のフォルダーに保存されているその他のファイルを subdir1 開くことができます。 認証のために Logon.aspx ファイルに自動的にリダイレクトされることはありません。

  4. 手順 3 を繰り返して、認証されていないユーザーによるアクセスを許可する他のページまたはフォルダーを特定します。

関連情報