[英]IIS 8.5 configuration on startup.cs (Azure webrole)
using (ServerManager serverManager = new ServerManager())
{
var config = serverManager.GetApplicationHostConfiguration();
// Configure IIS to compress for requests coming through proxies (CDN).
var httpCompressionSection = config.GetSection("system.webServer/httpCompression");
httpCompressionSection["noCompressionForHttp10"] = false;
httpCompressionSection["noCompressionForProxies"] = false;
httpCompressionSection["staticCompressionIgnoreHitFrequency"] = true;
// Configure IIS threshold and time-period for compression
var serverRuntimeSection = config.GetSection("system.webServer/serverRuntime");
serverRuntimeSection["frequentHitThreshold"] = 1;
serverRuntimeSection["frequentHitTimePeriod"] = new TimeSpan(24, 0, 0); // 1 day
// Configure IIS to compress files beforehand
var urlCompressionSection = config.GetSection("system.webServer/urlCompression");
urlCompressionSection["dynamicCompressionBeforeCache"] = true;
serverManager.CommitChanges();
}
When I run this code locally, everything works as expected (locally means windows 10 + IIS express). 当我在本地运行此代码时,一切都按预期工作(本地意味着Windows 10 + IIS Express)。 When I deploy this webrole to Azure, my machine (windows server 2012 R2 + IIS) crashes. 当我将此webrole部署到Azure时,我的计算机(Windows Server 2012 R2 + IIS)崩溃。
I can't debug this code on my deployed machine (not to my knowledge at least) so I'm trying to understand what's wrong with this code. 我无法在部署的机器上调试此代码(至少据我所知),所以我试图了解此代码的问题。
You should use an error logging technology like log4net to create a log for you of the error that is being thrown. 您应该使用log4net之类的错误记录技术为您创建正在抛出的错误的日志。
Try something similar to: 尝试类似的方法:
try {
using (ServerManager serverManager = new ServerManager())
{
var config = serverManager.GetApplicationHostConfiguration();
// Configure IIS to compress for requests coming through proxies (CDN).
var httpCompressionSection = config.GetSection("system.webServer/httpCompression");
httpCompressionSection["noCompressionForHttp10"] = false;
httpCompressionSection["noCompressionForProxies"] = false;
httpCompressionSection["staticCompressionIgnoreHitFrequency"] = true;
// Configure IIS threshold and time-period for compression
var serverRuntimeSection = config.GetSection("system.webServer/serverRuntime");
serverRuntimeSection["frequentHitThreshold"] = 1;
serverRuntimeSection["frequentHitTimePeriod"] = new TimeSpan(24, 0, 0); // 1 day
// Configure IIS to compress files beforehand
var urlCompressionSection = config.GetSection("system.webServer/urlCompression");
urlCompressionSection["dynamicCompressionBeforeCache"] = true;
serverManager.CommitChanges();
}
} catch (Exception e)
{
_log.ErrorFormat("Exception thrown during configuration! : {0}", e.ToString());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.