开发者

Is it possible to read IIS re-write rules from an Azure ServiceConfiguration file?

Is it possible to rea开发者_Python百科d the IIS re-write rules from the Azure ServiceConfiguration file instead of the web.config?

The problem that is arising is that we have friendly urls to certain weekly updated pages that are content managed, so a new url is created every week. The old ones are stored in a newslist archive so overwriting is not an option.

We would like to try and avoid having to upload the Azure site files every week, and want to be able to respond quickly (immediately) to possible link changes by altering values in the serviceconfig.

Anyone have any idea if this is possible or wether there is another solution?

Thanks


Yes, you can change your role to modify the web.config at runtime using the Configuration editor classes in the IIS Admin api. I haven't tried this, but it should enable you to load the settings from Azure config during startup then apply to the runtime instance of your role. So you would set this likely in your Application_start section of the web role's global.asax.

Alternatively, you could programitically build up the web.config at role start time using a Startup Task.

For the 1st approach:

Do some research at iis.net and then read this IIS forum post: http://forums.iis.net/t/1150481.aspx

Take a sample from user ruslany (give credit where due, but pasting so you see it):

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();
        }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜