1

仮想ディレクトリを作成し、IIS7 と C# を使用してアクセス許可を設定しようとしています。これが私のコードのサンプルです:

using (ServerManager serverManager = new ServerManager(webSite))
{
    ConfigurationSection anonymousAuthenticationSection =
      config.GetSection(
          @"system.webServer/security/authentication/anonymousAuthentication",
          webSite);
    anonymousAuthenticationSection["enabled"] = true;

    serverManager.CommitChanges();
    return "true";
}

これは例外をスローし、メッセージは次のとおりです。

Cannot read configuration file due to insufficient permissions.

誰か助けてくれませんか?

編集

管理者権限で実行すると、「構成ファイルの読み取りを有効にします」という新しいエラーが表示されます。どの構成を読み取る必要があり、どのようにアクセスできるか教えてもらえますか?

4

2 に答える 2

0

ServerManagerobjを誤って使用していました。コンストラクターでWebサイト名を期待していませんでした。以下は、IIS7で匿名アクセスを設定する正しい方法です。

using (ServerManager serverManager = new ServerManager())
                {
                    Configuration config = serverManager.GetApplicationHostConfiguration();
                    ConfigurationSection anonymouseAuthenticationSetion =                                            config.GetSection("system.webServer/security/authentication/anonymousAuthentication", webSite);
                    anonymouseAuthenticationSetion["enabled"] = true;
于 2010-03-30T13:00:59.253 に答える
0

これは、アプリケーションに適切な権限がないようです。IIS7 の構成を操作できるようにするには、アプリケーションを実行するアカウントが管理者アカウントであるか、SYSTEM アカウントなどの信頼できるコンピューティング ベースによって認識されるアカウントである必要があります。

これを Visual Studio でデバッグする場合は、エクスプローラーの [管理者として実行] 機能を使用するか、クイック起動ツールバーから Visual Studio を起動してください。

于 2010-03-21T05:12:59.783 に答える