是的,你可以改变你的角色在IIS管理API使用配置编辑器类修改web.config在运行时。我没有尝试过,但它应该使您能够在启动过程中从Azure配置中加载设置,然后应用到角色的运行时实例。所以你可以在Web角色的global.asax的Application_start部分中设置它。
或者,您可以使用启动任务在角色启动时以编程方式构建web.config。
对于第一个办法:
在iis.net做一些调查,然后读这个IIS论坛帖子: http://forums.iis.net/t/1150481.aspx
采取从用户ruslany样本(给予信贷,到期,但粘贴所以你看到它):
using(ServerManager serverManager = new ServerManager()) {
Configuration config = serverManager.GetWebConfiguration("Default Web Site");
ConfigurationSection rulesSection = config.GetSection("system.webServer/rewrite/rules");
ConfigurationElementCollection rulesCollection = rulesSection.GetCollection();
ConfigurationElement ruleElement = rulesCollection.CreateElement("rule");
ruleElement["name"] = @"MyTestRule";
ruleElement["stopProcessing"] = true;
ConfigurationElement matchElement = ruleElement.GetChildElement("match");
matchElement["url"] = @"foo\.asp";
ConfigurationElement conditionsElement = ruleElement.GetChildElement("conditions");
ConfigurationElementCollection conditionsCollection = conditionsElement.GetCollection();
ConfigurationElement addElement = conditionsCollection.CreateElement("add");
addElement["input"] = @"{HTTP_HOST}";
addElement["pattern"] = @"www\.foo\.com";
conditionsCollection.Add(addElement);
ConfigurationElement actionElement = ruleElement.GetChildElement("action");
actionElement["type"] = @"Rewrite";
actionElement["url"] = @"bar.asp";
rulesCollection.Add(ruleElement);
serverManager.CommitChanges();
}