Changing the SiteMapDataSource’s XML filename at runtime
2011-11-17 10:44
411 查看
http://blogs.msdn.com/b/wriju/archive/2006/10/07/changing-the-sitemapdatasource_1920_s-xml-filename-at-runtime.aspx
ASP.NET 2.0 comes with set of very rich navigation controls like TreeView, Menu, SiteMapPath. Ideally these controls should load the values at runtime from any structured data sources, be it SQL or XML or TXT. The default and most commonly used provider
is XmlSiteMapProvider which accepts the data from XML file. But if you have to load different XML files at runtime, then … Here we go
Create two web.sitemap files
File 1 [web.sitemap]
=============
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="MyMenu 1" url="Default.aspx">
</siteMapNode>
</siteMap>
File 1 [web2.sitemap]
==============
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="MyMenu 2" url="Default.aspx">
</siteMapNode>
</siteMap>
Then put any navigation control in your aspx page with the SiteMapDataSource as data source.
The main trick is with the web.config settings. There you have to mention all the files as the provider collection like
<?xml version="1.0"?>
<configuration>
<system.web>
………
<siteMap defaultProvider="1SiteMap" enabled="true">
<providers>
<add name="1SiteMap" type="System.Web.XmlSiteMapProvider"siteMapFile="Web.sitemap"/>
<add name="2SiteMap" type="System.Web.XmlSiteMapProvider"siteMapFile="Web2.sitemap"/>
</providers>
</siteMap>
</system.web>
Then in the page load event of your page (where the SiteMapDataSource and navigation controls are) change the property SiteMapProvider like
protected void Page_Load(object sender, EventArgs e)
{
//The provider name mentioned in the web.config
SiteMapDataSource1.SiteMapProvider = "2SiteMap";
}
Hope this will help in simpler way, but it is recommended that you should use SqlSiteMapProvider for all dynamic scenarios.
Ref: http://weblogs.asp.net/scottgu/archive/2005/11/20/431019.aspx
ASP.NET 2.0 comes with set of very rich navigation controls like TreeView, Menu, SiteMapPath. Ideally these controls should load the values at runtime from any structured data sources, be it SQL or XML or TXT. The default and most commonly used provider
is XmlSiteMapProvider which accepts the data from XML file. But if you have to load different XML files at runtime, then … Here we go
Create two web.sitemap files
File 1 [web.sitemap]
=============
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="MyMenu 1" url="Default.aspx">
</siteMapNode>
</siteMap>
File 1 [web2.sitemap]
==============
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="MyMenu 2" url="Default.aspx">
</siteMapNode>
</siteMap>
Then put any navigation control in your aspx page with the SiteMapDataSource as data source.
The main trick is with the web.config settings. There you have to mention all the files as the provider collection like
<?xml version="1.0"?>
<configuration>
<system.web>
………
<siteMap defaultProvider="1SiteMap" enabled="true">
<providers>
<add name="1SiteMap" type="System.Web.XmlSiteMapProvider"siteMapFile="Web.sitemap"/>
<add name="2SiteMap" type="System.Web.XmlSiteMapProvider"siteMapFile="Web2.sitemap"/>
</providers>
</siteMap>
</system.web>
Then in the page load event of your page (where the SiteMapDataSource and navigation controls are) change the property SiteMapProvider like
protected void Page_Load(object sender, EventArgs e)
{
//The provider name mentioned in the web.config
SiteMapDataSource1.SiteMapProvider = "2SiteMap";
}
Hope this will help in simpler way, but it is recommended that you should use SqlSiteMapProvider for all dynamic scenarios.
Ref: http://weblogs.asp.net/scottgu/archive/2005/11/20/431019.aspx
相关文章推荐
- How to populate menu from the SiteMapDataSourc, Database, xml files.
- Read Sitemap as normal XMLDataSource with Authorization Filter
- 网站地图Sitemap.xml笔记
- PHP生成网站sitemap.xml
- Use sitemap and role management control the navigation menu
- Changing Target Web Service At Runtime
- 记录一个map-site.xml -Xmx 1000m 写成了 1000报错问题
- How to Create a site at the specified URL and new database (Command-Line Operation)
- Adding dynamic nodes to ASP.NET site maps at runtime by deriving from StaticSiteMapProvider
- XML declaration allowed only at the start of the document 问题解决方法
- sitemap.xml
- python测试sitemap.xml中的URL
- The process was terminated due to an internal error in the .NET Runtime at IP 7915EE73 (79140000) wi
- Changing the language of an existing SharePoint site
- CMS 内容页sitemap.xml 获取
- eclipse安装PyDev插件出错No software site found at jar:file:[离线包路径]!/. Do you wish to edit the location?
- 配置hive的坑 hive-site.xml:2787:3: The element type "configuration" must be terminated by the matching
- error on line 1 at column 6: XML declaration allowed only at the start of the document
- Adding dynamic nodes to ASP.NET site maps at runtime by deriving from StaticSiteMapProvider
- hadoop2.2.0 yarn-site.xml--Map Reduce configuration