Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c# - ApplicationHost.xdt in Azure Web Apps

How to change applicationHost.config in an Azure web app? I try:

using (ServerManager serverManager = new ServerManager())
{
    Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
    Microsoft.Web.Administration.ConfigurationSection webLimitsSection = config.GetSection("system.applicationHost/webLimits");

    webLimitsSection["connectionTimeout"] = TimeSpan.Parse("00:00:10");
    webLimitsSection["dynamicIdleThreshold"] = 150;
    webLimitsSection["headerWaitTimeout"] = TimeSpan.Parse("00:00:10");
    webLimitsSection["minBytesPerSecond"] = 500;

    serverManager.CommitChanges();
}

But catch exception:

Filename: ?D:Windowssystem32inetsrvconfigapplicationHost.config Error: Cannot write configuration file due to insufficient permissions

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The way to do this is to use XML Document Transforms (XDT) which is referenced here.

For your scenario, create a file called applicationhost.xdt that contains the following:

<configuration  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.applicationHost>
    <webLimits xdt:Transform="SetAttributes(connectionTimeout)"
               connectionTimeout="00:00:10" />
    <webLimits xdt:Transform="SetAttributes(dynamicIdleThreshold)"
           dynamicIdleThreshold="150" />
    <webLimits xdt:Transform="SetAttributes(headerWaitTimeout)"
               headerWaitTimeout="00:00:10" />
    <webLimits xdt:Transform="SetAttributes(minBytesPerSecond)"
               minBytesPerSecond="500" />
  </system.applicationHost>
</configuration>

Then, using an FTP client (I used FileZilla), copy it to the site folder (not wwwroot) for your web app.

enter image description here

Finally, restart your web app which you can do from the Azure portal.

You can verify the changes are applied using the Kudu site extension. After signing into Kudu, go to the Debug Console (CMD) window and drill down into the Logfiles folder and then the Transform folder.

enter image description here

In the Transform folder you will see a "*scm.log" file that will show the transformations. It should look something like this.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...