`
aerchi
  • 浏览: 422206 次
  • 性别: Icon_minigender_1
  • 来自: 昆明
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

I created a asp.net 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:

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

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, clickhere.

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:

<configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <remove value="default.aspx" />
        <add value="default.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

Works OK for us.


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics