简体   繁体   English

在startup.cs上的IIS 8.5配置(Azure webrole)

[英]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.

相关问题 Startup.cs安全措施 - Startup.cs security measures "将数据传递给 startup.cs" - Pass data to startup.cs 在startup.cs中播种数据 - Seeding data in startup.cs 在Visual studio 2022中,如何像startup.cs一样在Program.cs中添加IConfiguration和配置? - In Visual studio 2022, How To add IConfiguration and add configuration in Program.cs like startup.cs? how to read azure app config values in C# startup.cs class in azure function - how to read azure app config values in C# startup.cs class in azure function Dotnet core 3.0项目遇到cors问题,因为startup.cs中配置上传文件function - Dotnet core 3.0 project encounter cors issue because of configuration in startup.cs for uploading file function 在启动文件中将配置设置为app.UseAPIResponseWrapper()时如何在.NET Core中返回视图 - How to return view in .NET Core when configuration set to app.UseAPIResponseWrapper() in startup.cs file Net Core集成测试:从其他程序运行Startup.cs和配置 - Net Core Integration Test: Run Startup.cs and Configuration from other Program 在 Azure Function 中引用类库 .dll 文件,是否需要在 Startup.cs 中设置服务? - Referencing class library .dll file in Azure Function, do I need to setup the services in Startup.cs? 连接到 .NET 3.1 中的 Entity Framework Core - Connect to Entity Framework Core in .NET 3.1 Azure Function Project Startup.cs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM