如何将HttpError ConfigurationElement还原回"Inherited"(继承).使用IIS 7 API [英] How to revert an HttpError ConfigurationElement back to "Inherited" using IIS 7 API
问题描述
假设我在web.config
中具有以下<httpErrors>
集合:
<httpErrors>
</httpErrors>
是的,很好'n为空.
在IIS 7中,我的HTTP错误页面如下所示:
美丽! (我之所以突出显示404是因为这是我将在几秒钟内使用的示例).
现在,我运行以下代码:
errorElement["statusCode"] = 404;
errorElement["subStatusCode"] = -1;
errorElement["path"] = "/404.html";
httpErrorsCollection.Add(errorElement);
可爱.现在,正如我在web.config
中所期望的那样:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/404.html" />
</httpErrors>
再开心不过了.现在,在IIS 7中,"HTTP错误"部分按预期显示,如下所示:
在这一点上,生活再好不过了.现在,我想以编程方式将我的404错误还原为原始屏幕截图所示的状态.逻辑表明我应该remove
我的新错误:
httpErrorsCollection.Remove(errorElement);
但是,如果我这样做,我的web.config
看起来很像这样:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
</httpErrors>
我的IIS看起来像这样:
这是由于我的web.config
而引起的-但是,如何使用ServerManager
及其所有有用的IIS 7 API,完全删除httpError
元素并将我的web.config
还原为:
<httpErrors>
</httpErrors>
有什么想法吗?
在IIS7及更高版本的管理部分下,我们可以看到一个名为配置编辑器的图标, 双击并扩展至
system.webserver-> webdav-> httpErrors
在
下的默认路径上右键单击
部分->单击还原为父对象"
然后重新启动网站
所做的更改将被还原
Suppose I have the following <httpErrors>
collection in a web.config
:
<httpErrors>
</httpErrors>
Yep, nice 'n empty.
And in IIS 7, my HTTP errors page looks like this:
Beautiful! (I've highlighted 404 simply because that's the example I'll use in a sec).
Now, I run the following code:
errorElement["statusCode"] = 404;
errorElement["subStatusCode"] = -1;
errorElement["path"] = "/404.html";
httpErrorsCollection.Add(errorElement);
Lovely. I now have, as expected this in my web.config
:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/404.html" />
</httpErrors>
Couldn't be happier. Now, in IIS 7 my HTTP errors section looks, as expected, like below:
Life couldn't be sweeter at this point. Now, down the line, I want to programmatically revert my 404 error back to the state shown in the original screenshot. Logic dictates that I should remove
my new error:
httpErrorsCollection.Remove(errorElement);
But alas, if I do this, my web.config
looks a lot like this:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
</httpErrors>
And my IIS looks a bit like this:
This is expected because of my web.config
- but how, using ServerManager
and all it's useful IIS 7 API, do I remove the httpError
element entirely and revert my web.config
back to:
<httpErrors>
</httpErrors>
Any ideas?
In IIS7 and above under Management section, we can see an icon named Configuration Editor, double click and expand to
system.webserver-->webdav-->httpErrors
Right click on Default path, under
section-->Click on Revert to Parent
Then restart the website
The changes will be reverted back
这篇关于如何将HttpError ConfigurationElement还原回"Inherited"(继承).使用IIS 7 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!