0

WebDav 発行を有効にするように IIS 仮想フォルダーを構成したいと考えています。手動で簡単に行うことができますが、C# でコードを介して同じことをしたかったのです。サイトや仮想ディレクトリを作成したり、MIME タイプなどのプロパティをそれらに追加したりするのは問題ありませんが、applicationHost.config ファイルにあるはずの WebDav 設定にアクセスできないようです。私はこのように何度も試みました。明らかに、このスニペットは何もしません。これは、私が何をいじっていたかを示すためだけのものです。

using (var serverManager = new ServerManager())
{
    try
    {
        var app = serverManager.Sites.FirstOrDefault(o => o.Name.Equals("custom"))?.Applications.First(o => o.Path.Equals("/"));
        var config = serverManager.GetApplicationHostConfiguration();
        var web = serverManager.GetWebConfiguration("custom");
        var setting = config.RootSectionGroup;
        var admin = serverManager.GetAdministrationConfiguration();

        serverManager.CommitChanges();
    }
    catch (Exception e)
    {
        Console.WriteLine($"Error when creating virtual directory: {e.Message}");
    }
}

これらすべての方法を試してみましたが、applicationHost.config ファイルの最後にあるこれらのセクションにアクセスできないようです。2 つ目は、私の仮想フォルダーです。WebDav 機能がアクティブです。いくつかのアプリケーションを使用して接続を試みましたが、正常に動作します。私に何ができる?前もって感謝します。

<location path="custom">
    <system.webServer>
        <security>
            <requestFiltering>
                <fileExtensions applyToWebDAV="false" />
                <verbs applyToWebDAV="false" />
                <hiddenSegments applyToWebDAV="false" />
            </requestFiltering>
        </security>
        <webdav>
            <authoring enabled="true">
                <properties allowAnonymousPropfind="true" />
            </authoring>
        </webdav>
    </system.webServer>
</location>
<location path="custom/local">
    <system.webServer>
        <webdav>
            <authoringRules>
                <add users="*" path="*" access="Read" />
            </authoringRules>
        </webdav>
    </system.webServer>
</location>
4

1 に答える 1

1

私のテストでは、仮想ディレクトリ内の authoringRules の構成を含め、コードを使用してこの操作を実行できることが証明されています。

 using (ServerManager serverManager = new ServerManager())
        {
            try
            {

                Configuration config = serverManager.GetApplicationHostConfiguration();

                ConfigurationSection authoringRulesSection = config.GetSection("system.webServer/webdav/authoringRules", "Default Web Site/a");

                ConfigurationElementCollection authoringRulesCollection = authoringRulesSection.GetCollection();

                ConfigurationElement addElement = authoringRulesCollection.CreateElement("add");
                addElement["roles"] = @"administrators";
                addElement["path"] = @"*";
                addElement["access"] = @"Read, Write, Source";
                authoringRulesCollection.Add(addElement);

                serverManager.CommitChanges();
                Console.WriteLine("success");
            }
            catch (Exception e)
            {
                Console.WriteLine("failed"+e.Message);
            }
        }

したがって、コードは操作を実行しないと思います。何か問題がある可能性があります。デバッグ モードで問題を探すことをお勧めします。

コードによる詳細な構成については、このドキュメントを参照してください。

于 2020-11-30T03:55:48.590 に答える