在Microsoft.Web.Administration.Application对象上配置SSL? [英] Configure SSL on a Microsoft.Web.Administration.Application object?

查看:291
本文介绍了在Microsoft.Web.Administration.Application对象上配置SSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决如何以编程方式启用需要SSL复选框并在IIS应用程序中使用 Microsoft.Web.Administration 。

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 site itself, but I need only need to turn it on for a few Applications hosted on the site.

任何人都有这方面的经验吗?

Anyone have experience doing this?

我试过这个开始:

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

但我收到错误:


文件名:
\?\ C:\ Windows \system32 \inetsrv \ config \ applicationHost.config错误:
无法写配置文件

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

这很奇怪,因为根据我的阅读,我收集该文件维护IIS配置,但它在Windows中不存在(我无法在TextPad中打开它,但它确实存在于命令提示符中,我可以更多它。

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";

其中siteName和vdRelativePath是默认网站和/Application/Path\".

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

如果默认网站/应用程序/路径没有,您可以使用 config.GetLocationPaths()查找正确的路径为你工作。

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

这篇关于在Microsoft.Web.Administration.Application对象上配置SSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆