iis-7 - 是否可以从 Azure ServiceConfiguration 文件读取 IIS 重写规则?

标签 iis-7 url-rewriting azure

是否可以从 Azure ServiceConfiguration 文件而不是 web.config 读取 IIS 重写规则?

出现的问题是,我们对某些每周更新的内容管理页面有友好的 URL,因此每周都会创建一个新的 URL。旧的存储在新闻列表存档中,因此无法覆盖。

我们希望尝试避免每周上传 Azure 站点文件,并希望能够通过更改 serviceconfig 中的值来快速(立即)响应可能的链接更改。

有人知道这是否可行或是否有其他解决方案?

谢谢

最佳答案

是的,您可以使用 IIS 管理 API 中的配置编辑器类来更改您的角色以在运行时修改 web.config。我还没有尝试过这个,但它应该使您能够在启动期间从 Azure 配置加载设置,然后应用于您的角色的运行时实例。因此,您可以在网络角色的 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();
        }

关于iis-7 - 是否可以从 Azure ServiceConfiguration 文件读取 IIS 重写规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5299197/

相关文章:

asp.net-mvc - Azure 门户中的应用程序设置不会覆盖通用值

asp.net - IIS7 部署 - 重复 'system.web.extensions/scripting/scriptResourceHandler' 部分

c# - 使用 ServerManager 类配置 IIS 身份验证设置

c# - validateRequest ="false"在 ASP.NET 2.0 中不起作用

grails - 在 Grails URL 中包含名称

.htaccess - 索引文件动态子域冲突的htaccess规则

c# - 在 Azure Function .net 5 中处理 blob 触发器时出现 Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException

visual-studio - Visual Studio 2010 发布/网络部署问题

ASP.net WebForms 无扩展 URL

python - 如何仅获取已识别的文本?