开发者

Configure SSL on a Microsoft.Web.Administration.Application object?

开发者 https://www.devze.com 2023-04-08 19:19 出处:网络
I\'m having a little trouble figuring out how to programatically enable the \"Require SSL\" check box and change the \"Client Certificates\" option to \"Require\" in IIS Application using Microsoft.We

I'm having a little trouble figuring out how to programatically enable the "Require SSL" check box and change the "Client Certificates" option to "Require" in IIS Application using Microsoft.Web.Administration.

All of the questions on the net I've found relate to configuring it on the web sit开发者_C百科e itself, but I need only need to turn it on for a few Applications hosted on the site.

Anyone have experience doing this?

I tried this to start:

application.EnabledProtocols = "http,https";
serverManager.CommitChanges();

But I got an error:

Filename: \?\C:\Windows\system32\inetsrv\config\applicationHost.config Error: Cannot write configuration file

Which is odd, because from what I've read, I gather that file maintains IIS configuration, but it doesn't exist in Windows (I can't open it in TextPad), but it does exist in the command prompt and I can more it.


Did more searching, found this, ended up writing this:

ServerManager serverManager = new ServerManager();
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", siteName + "/" + vdRelativePath);
accessSection["sslFlags"] = "Ssl,SslRequireCert";

Where siteName and vdRelativePath are "Default Web Site" and "/Application/Path".

You can use config.GetLocationPaths() to find the right path if "Default Web Site/Application/Path" doesn't work for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号