i have this situation: i have to build a menu with datasource from the db, because i have to filter them among the user that is loged in. i have tried building a menu using repeater, and all this works fine till i realized that i wanted the menu with more than two levels. i have also tried with treeview, but i really don't want this solution (problem with the style and the treeview doesn't have a pretty view).
Could anyone give me just the idea ?
thnx in advance.
If you are securing your pages in the conventional sense (ie--using ASP.NET's builtin permissions system), you can just use the normal SiteMapProviders as they will security trim menus for you.
If you need to do custom, try making a class that implements IHeirarchicalDataSource and then bind anything appropriate (eg--ASP.BulletedList) to that.
Related
I have been doing typical menu from code behind where i just show and hide divs based on their role but code becomes very long cause i have to hide every single div of each role for each user.
My question is... Is there a better practice to do this? I also just found out about Login View, is this the way to go in Web Forms?
Your code behind should not take the responsibility of altering how the View is displayed, that's the job of the view (and that's why asp controls exist).
One approach would be to have a logic that builds up a List and this list is passed as DataSource of an asp control.
Actually there's a good control that allows you to iterate a collection of elements defining a display template for each element in that list, here you can find the details:
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeater?view=netframework-4.7.2
I hope this sets you in the right path.
A common way to do this is in a WebForms app is to use a SiteMap.
A site map can be linked to roles, so that only those elements that are accessible for a user's roles are displayed. And recent versions can be made to display reasonable cleanly, as divs that can be styled how you want (the original version generated a lot if inline styles).
For an MVC sitemap there are similar solutions, such as this one.
I'm working for a project where the menu bar needs to be a dynamic menu interacting with the roles defined for the users. It works with the Symfony 3.3.
The concept should be like this: '1' user have 'n' roles and each role should see 'm' options in the menu bar. And also, different roles can have the same option menu available. So the result shouldn't show the same option twice.
I've been exploring the different kinds of menus in the list of bundles availables and no one seems to match to this idea.
I know how to do it by myself but I wonder if anyone knows if exist any bundle who have this functionality or very similar to be able to use it or modify it easily to be able to use it.
The one I saw but it's not all I need is the most used for menus but I don't think can manage the role concept. If I'm wrong tell me plx.
What you suggest to do?
Thank you very much for your help!
Follow this symfony documentation knpMenuBundle
I have created a site which has some roles. and each user can have some roles. every role has permission to some pages.
I want to build menus dynamically depending on user roles so every user can see his available pages in his menu.
I want to know that what is the best way to do this? using an XML to describe this menus hierarchy and specify each role available menus or there is better way to do this?
Rather than reinventing the wheel, I'd strongly suggest using Telerik's Extensions for ASP.NET MVC.
It includes a powerful Menu extension and has good programmability. I've used the .Visible() method along with IPrincipal.IsInRole() to determine which menus are available and when.
What's better is that it's free and open source! There's a paid-for version with support, but community and forum support seems to be quite good enough.
we have a mysql database that has the roles and objects and a decision is made at run time based on the logon user as to who gets to see what. There is also a decision made on individual pieces or controls on the page. There can also be tests on the pages themselves to make sure it's not just a menu that's hiding a page.
I used the MVC sitemap project in combination with a "Security Trimming" link helper ( "Security aware" action link? ) for this sort of thing before. Pretty easy.
I mainly do C# ASP.NET projects in VS2010. Once you've put masterpages and other things in place, I find the design view pretty much goes grey and elements can't be selected. This isn't so bad except that sometimes you need to access the little 'smart tags' at the top right of controls to do things.
In particular I'm trying to do this with some telerik controls, though the issue isn't confined to them.
Anyone have a handy tip to access this functionality (or miraculously make design view work!) ?
Thanks!
PS. I read in a few places that Shift-Alt-F10 may help. I tried putting my cursor in the control's tag and using it, no luck. Also I clicked the little rectangle below design view to select the control and tried it again- no luck.
Yeah, searching for VS design-time troubleshooting tips in the asp.net forums or MSDN is probably the best start to identify and eliminate the abnormal behavior.
Here is one trivial question, that I am not sure how to handle.
I need to display list of categories on every page, and to be able to choose items from a specific category to be displayed. I use asp.net MVC, and have chosen to create a user control that will display categories. My question is: what is the best approach to pass data to a user control. I already found some information in these blog posts:
http://weblogs.asp.net/stephenwalther/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx
http://blog.matthidinger.com/2008/02/21/ASPNETMVCUserControlsStartToFinish.aspx
I would like also to hear your opinion.
PS. I'd like to hear Jeff's opinion, especially because of his experience with UC's on Stackoverflow
I'm using mvc components, which replaced ascx user controls in preview 4.
Example:
http://blog.wekeroad.com/blog/asp-net-mvc-preview-4-componentcontroller-is-now-renderaction/
So, you call components action from View, which then choose View to render. You can pass data in this call also.
it is the mvc futures project. i will probably try this
http://forums.asp.net/t/1303328.aspx. I need to render menu with categories.