Web.config中的siteMap问题

时间:2013-01-22 14:15:18

标签: c# asp.net visual-studio-2010

Web.config的问题。 siteMap不起作用。 VS2010。

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
        <providers>
          <add name="XmlSiteMapProvider"
            description="Default SiteMap provider."
            type="System.Web.XmlSiteMapProvider "
            siteMapFile="Web.sitemap"
            securityTrimmingEnabled="true" />
        </providers>
 </siteMap> 

我认为它没有看到'Web.sitemap'。 标签'add'中的Intellisense建议only-lockAllAttributesExcept,lockAllElementsExcept,lockAttributes,lockElements,lockItem - parameters。 但是不建议使用params描述,siteMapFile,securityTrimmingEnabled。

可能是什么原因? 请咨询。

Web.config内容是:

<?xml version="1.0"?>

<configuration>
  <connectionStrings>

    <add name="SqlRoleManagerConnection" 
         connectionString="Data Source=server_name;Integrated Security=false;Initial Catalog=DB_XXX;User ID=User_XXX;Password=PASSWD_XXX" 
         providerName="System.Data.SqlClient" />    
  </connectionStrings>


  <location path="Approver.aspx">
      <system.web>
          <authorization>
              <allow roles="Approvers"/>
              <deny users="*"/>
          </authorization>
      </system.web>
  </location>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Windows"/>

    <authorization>
        <deny users="?"/>
    </authorization>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="true" defaultProvider="SqlRoleManager">
      <providers>
        <clear/>
        <add name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="SqlRoleManagerConnection" applicationName="HSE_Monitoring_Application" />
      </providers>

    </roleManager>


    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
      <providers>
        <add name="XmlSiteMapProvider" 
          description="Default SiteMap provider."
          type="System.Web.XmlSiteMapProvider"
          siteMapFile="Web.sitemap"
          securityTrimmingEnabled="true" />
      </providers>
    </siteMap>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Web.sitemap内容是:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

  <siteMapNode url="default.aspx" title="Home">
      <siteMapNode url="approver.aspx" title="Approver Expenses" roles="Approvers" />
      <siteMapNode url="audit/auditor.aspx" title="Audit Page" roles="Auditors" />
      <siteMapNode url="admin/admin.aspx" title="Admin Manager" roles="Admins" />
  </siteMapNode>

</siteMap>

关于!

1 个答案:

答案 0 :(得分:0)

web.sitemap文件是ASP.NET的默认站点地图提供程序,因此无需在<siteMap ...中指定web.config即可运行。另外,请考虑在路径中使用~/作为前缀:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/default.aspx" title="Home">
      <siteMapNode url="~/approver.aspx" title="Approver Expenses" roles="Approvers" />
      <siteMapNode url="~/audit/auditor.aspx" title="Audit Page" roles="Auditors" />
      <siteMapNode url="~/admin/admin.aspx" title="Admin Manager" roles="Admins" />
  </siteMapNode>
</siteMap>