导航菜单不会重定向到给定值
我遇到的问题涉及导航菜单中的重定向。我想动态创建一个导航菜单。根据用户的角色,我们可以看到所需的导航菜单项。 目前我使用:
if (found)
{
if (admin == true)
{
NavigationMenu.Items.Add(new MenuItem("Agenda", "/AdminPages/Agenda.aspx"));
NavigationMenu.Items.Add(new MenuItem("Add Product", "/AdminPages/ProductToevoegen.aspx"));
}
else if (user == true)
{}
此代码已放置在我的 Site.master.cs 中,但我的 login.aspx.cs 代码中也有一个控件,该控件执行 Response.Redirect("~/AdminPages/Agenda. aspx");
到某个页面,具体取决于登录后的管理员或用户。现在我遇到的问题是,当我登录时,一部分起作用,因此它控制角色并添加所需的导航菜单项。但是,当我单击“添加产品”链接时,它不会将我重定向到该页面。它不断将我重定向到:
http://localhost:52853/AdminPages/Agenda.aspx
在网址栏中,它实际上显示了单击时后跟 # 的网址,然后重定向到议程页面。
关于如何解决这个问题有什么想法吗?我尝试找到一种方法将导航链接放入 login.aspx.cs 代码中,但找不到引用 NavigationMenu 的正确方法,不知道这是否会产生任何帮助。先感谢您。
the problem i encounted concerns redirecting in the navigation menu. I'd like to dynamicly create a navmenu. Depending on what role the user has we get to see the required navigation menu items.
At the moment i use:
if (found)
{
if (admin == true)
{
NavigationMenu.Items.Add(new MenuItem("Agenda", "/AdminPages/Agenda.aspx"));
NavigationMenu.Items.Add(new MenuItem("Add Product", "/AdminPages/ProductToevoegen.aspx"));
}
else if (user == true)
{}
This code I have placed in my Site.master.cs, but I also have a control in my login.aspx.cs code which does a Response.Redirect("~/AdminPages/Agenda.aspx");
to a certain page depending on admin or user once logged in. Now the problem I have is that when I log in, a part works, so it controls the role and adds the required navigation menu items. But when I click for example on the Add Product link it doesn't redirect me to the page. It keeps redirecting me to :
http://localhost:52853/AdminPages/Agenda.aspx
In the url bar it actually shows the url followed with a # when clicked and than redirect to the Agenda page.
Any ideas on how to fix this problem? I tried finding a way to put the navigation links in the login.aspx.cs code aswell but couldn't find the correct way to refer to the NavigationMenu, don't know if that could be off any help. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用标准 siteMap 对象和 RoleProvider。并阅读一些有关安全调整的内容(您可以在站点地图节点上指定哪些角色可以访问哪些站点)。
I would suggest using a standard siteMap object and RoleProvider. And read a little bit about security trimming (you can specify on your sitemap nodes which roles can access which sites).
嗯,可能不是正确的方法,但我修复了它,在 site.master.aspx 文件中创建了另一个菜单,例如 MenuAdmin。比在后面的代码中我设置了
并且
似乎工作正常,做了现在需要做的事情;)
Hm might not be the correct way but i fixed it making another menu in the site.master.aspx file called MenuAdmin for example. Than in the code behind i've set the
and
Seems to work fine, does what it needs to do for now ;)
查看创建新 MenuItem 的参数。
当仅传递 2 个参数时,您将填充文本和值参数。您要传递的是一个navigateUrl 参数。仅当传递 imageURL 参数(可以为空)时才可用。
类似下面的内容应该可以解决您的问题。
希望这有帮助。
Look at the parameters for creating a new MenuItem.
When only passing 2 parameters, you are filling the text and value parameters. What you want to pass is a navigateUrl parameter. This is only available when passing an imageURL parameter (which can be empty).
Something like the following should fix your problem.
Hope this helps.