动态更改网站的菜单项 [英] Dynamically change the menu items of website

查看:58
本文介绍了动态更改网站的菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

在我的网站上,我正在通过包含母版页来显示菜单,现在我要根据登录更改来更改菜单,我该怎么做

Ankita mali

Dear Sir,

In my website i am displaying menu by including master pages ,now i want to change the menus according to login change ,how can i do that

Ankita mali

推荐答案

按照此示例进行操作,在这里我正在使用xml文件创建菜单.

Follow this example , here i am creating menu using xml file.

xml file-



<sitemap>

<sitemapnode url="Default.aspx" title="Home">

<sitemapnode title="Products" description="Our Products">

<sitemapnode url="Product1.aspx" title="My Products">

description="These are my products" />

<sitemapnode url="Product2.aspx" title="New Products">

description="Some new products " />

</sitemapnode>

<sitemapnode title="Services" description="Our Services">

<sitemapnode url="Service1.aspx" title="ASP.NET Consulting">

description="Best ASP.NET Consulting" />

<sitemapnode url="Service2.aspx" title="ASP.NET Training">

description="Best ASP.NET Training" />

</sitemapnode>

</sitemapnode>

</sitemapnode></sitemapnode></sitemapnode></sitemapnode></sitemap>



现在,使用此代码通过xml设计菜单.



Now use this code to design menu using xml.

private void CreateMenuWithXmlFile()

{

string path = @"C:\MyXmlFile.xml";

DataSet ds = new DataSet();

ds.ReadXml(path);

Menu menu = new Menu();

menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);

for (int i = 0; i < ds.Tables.Count; i++)

{

MenuItem parentItem = new MenuItem((string)ds.Tables[i].TableName);

menu.Items.Add(parentItem);

for (int c = 0; c < ds.Tables[i].Columns.Count; c++)

{

MenuItem column = new MenuItem((string)ds.Tables[i].Columns[c].ColumnName);

menu.Items.Add(column);

for (int r = 0; r < ds.Tables[i].Rows.Count; r++)

{

MenuItem row = new MenuItem((string)ds.Tables[i].Rows[r][c].ToString());

parentItem.ChildItems.Add(row);

}

}

}

Panel1.Controls.Add(menu);

Panel1.DataBind();

}



跟随此链接也-

http://www.codeproject.com/KB/menus/PopulatingMenuControlASP2.aspx

希望这会对您有所帮助.



follow this link also-

http://www.codeproject.com/KB/menus/PopulatingMenuControlASP2.aspx

Hope this will help you.


您可以将菜单项绑定到站点地图并使用role属性.为此,您将需要在Web.Config中启用安全修整".这是最简单的方法.

网站导航概述:http://msdn.microsoft.com/zh-cn/library/e468hxky.aspx


安全整理信息:http://msdn.microsoft.com/zh-cn/library/ms178428.aspx


SiteMap绑定信息:http://www.w3schools.com/aspnet/aspnet_navigation.asp


好的教程/概述在这里:

http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and- security-don-t-match-up.aspx


另一个可行但不太理想的选项是使用loginview控件,该控件可以基于角色显示控件.这可能是最快(但灵活性/性能最低)的选项.您可以在此处找到指南:

http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx
You can bind the menu items to a site map and use the roles attribute. You will need to enable Security Trimming in your Web.Config to do this. This is the simplest way.

Site Navigation Overview: http://msdn.microsoft.com/en-us/library/e468hxky.aspx


Security Trimming Info: http://msdn.microsoft.com/en-us/library/ms178428.aspx


SiteMap Binding Info: http://www.w3schools.com/aspnet/aspnet_navigation.asp


Good Tutorial/Overview here:

http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx


Another option that works, but is less ideal is to use the loginview control which can display controls based on role. This might be the quickest (but least flexible/performant) option. You can find a guide here:

http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx


这篇关于动态更改网站的菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆