how to solve Error cannot add duplicate collection entry of type add with unique key attribute 'valu

I created a website and published it in iis 7. I deleted the default website option in the iis 7 and created the new website in the iis 7. When i click the default document I got the error like "Error cannot add duplicate collection entry of type add with unique key attribute 'value' set to index.aspx". I used the following code in my web.config file.

IIS7 defines a defaultDocument section in its configuration files which can be found in the %WinDir%\System32\InetSrv\Config folder. Most likely, the file index.aspx is already defined as a default document in one of IIS7's configuration files and you are adding it again in your web.config.

I suspect that removing the line <add value="index.aspx" />

from the defaultDocument/files section will fix your issue.

The defaultDocument section of your config will look like:

    <remove value="default.aspx" />
    <remove value="index.html" />
    <remove value="iisstart.htm" />
    <remove value="index.htm" />
    <remove value="Default.asp" />
    <remove value="Default.htm" />

Note that index.aspx will still appear in the list of default documents for your site in the IIS manager.

For more information about IIS7 configuration, click here.

The ideal scenario is to have <add value="default.aspx" /> in config so the application can be deployed to any server without having to reconfigure. IMHO I think the implementation within IIS is poor.

We've used the following to make our default document setup more robust and as a result more SEO friendly by using canonical URL's:

        <remove value="default.aspx" />
        <add value="default.aspx" />

Works OK for us.

发布了430 篇原创文章 · 获赞 415 · 访问量 925万+


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客