I have a custom menu, which leverages the standard asp.net sitemap. It works well but some of my pages are dynamically generated by URL rewriter, so they don't sit in the sitemap XML file. At the moment I rolled a custom solution which shows/hides menu items via CSS class and a programmatic check of the role that the user is in. It works ok until I visit a dynamic page that doesn't exist in the sitemap file. I've tried the "roles" attribute in the sitemap file with security trimming but it isn't working because I have a custom menu.
Is there a way I could leverage the roles attribute in the sitemap file to show/hide menu items for my custom control below, even when some pages are not in the sitemap? My menu control is below...
<div class="menu">
<ul>
<asp:Repeater ID="rpt" runat="server" DataSourceID="smdsMenuPrimary"
EnableViewState="False">
<ItemTemplate>
<li class="<%#GetDisplayClass((SiteMapNode)Container.DataItem)%>"><a href='<%# ((SiteMapNode)Container.DataItem).Url %>'><%# ((SiteMapNode)Container.DataItem).Title %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
You can use UrlAuthorizationModule.CheckUrlAccessForPrincipal(path) to test each URL from the site map - this method returns true if user has access to the path (file or folder) and false otherwise.
Related
My project is built on the WebForm architecture. It uses role-based authorization of the standard ASP.NET Identity mechanism. I had a question how to dynamically create an html markup fragment, for example, if the role is an administrator, then the user sees the markup like this:
<li><a runat="server" href="~/WebLogisticTool>UploadContainerExcel</a></li>
<li><a runat="server" href="~/Home>Home</a></li>
<li><a runat="server" href="~/AdminPanel>AdminPanel</a></li>
if the role is a manager then:
<li><a runat="server" href="~/About>About</a></li>
<li><a runat="server" href="~/Home>Home</a></li>
Create table with userrights with menu options.
While login get data from this table for menu options and bind this options using element or using Repeater control
We have a Sitecore project and the code/files are from an ASP.NET web application.
The HTML for the products section is as follows
<div class="products-section">
<ul class="tabs">
<li>Product 1</li>
<li>Product 2</li>
</ul>
<div class="product">
<h3>Product Name</h3>
<img src="/images/img1.jpg" />
<span>Description</span>
</div>
</div>
This is how it works for an end user.
EU will click on a Product tab (eg: Product 1), which will change the content inside <div class="product">, without postback.
For the author, this section must be editable from the Experience editor. Usually, I would use asp:Repeater with sc:Text,sc:Image to render it.
But, here the data has to be retrieved using ajax calls, which means no Repeater or Sitecore controls.
In such case, how can I make the content editable from Experience editor.
The only ideas I came up with:
Get data of all the products in Page_Load, bind it using Repeater and then use jQuery to Show/Hide the respective divs. (doesn't seem a nice way though)
Tell the content author, that this section can only be edited from Content editor and not from the experience editor :)
What are my options here.
One option could be to render your page differently when in the experience editor. Check the mode in your code and use a repeater when editing, otherwise use the jquery output.
You can use Views to easily display/hide the output you want.
<asp:MultiView runat="server" ID="ProductsView">
<asp:View runat="server" ID="StandardView">
<div ...>
...
</div>
</asp:View>
<asp:View runat="server" ID="EditorView">
<asp:Repeater..>
...
</asp:Repeater>
</asp:View>
</asp:MultiView>
In your code behind:
ProductsView.SetActiveView((Sitecore.Context.PageMode.IsExperienceEditor || Sitecore.Context.PageMode.IsExperienceEditorEditing) ? EditorView : StandardView)
Based on the active view, you can decide to attach data to the repeater or not (don't do that when the StandardView is active, for performance)
I'm not sure why would an end user interact with Experience Editor as Experience editor is used by Content Authors for authoring the site and updating the content on the Page itself.
But if this is a requirement for a Content Author you can use the sitecore services client api for updating the content using ajax call.
Use this document to see how ssc works.
Let me know if you have a different ask.
When creating a standard asp.net web site with vs2013 I notice that no site map is used and I also note that the menu created is a new nav bar class.
You get this as a default:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/About">About</a></li>
<li><a runat="server" href="~/Contact">Contact</a></li>
<li><a runat="server" href="~/Upload">Upload Files</a></li>
<li><a runat="server" href="~/Portal/UploadCust">Customer Portal</a></li>
</ul>
So, no site map is used here. And the menu system in asp.net NOW does not use the site.map. What is the suggested approach NOW THAT NO SITEMAP is used in these templates to hide a given menu based on role?
Is the suggestion to create a sitemap by hand? and then simply enable trimming as was done in the past? I have role permissions working fine (sql providers) but I am perplexed why this new menu system does not support nor have anything to do with site maps? I am simply looking to hide menu options based on role membership but am at a loss as to why the default menu systems don't use sitemap anymore? Right now users just get a 404 error.
So is some suggested way to hide menu options in above or is it still best to adopt a site map and enable trimming? This being the case then must I drop use of the above new nav bar class?
edit:my current solution is to add a id like this
"<a id="PortalLink" runat="server" href="~/Portal/UploadCust">Customer Portal</a>
And then in the web site on-load in VB, I use this:
If Roles.IsUserInRole("Portal") Then
Me.PortalLink.Visible = True
Else
Me.PortalLink.Visible = False
End If
I'm just starting web-developing now (I do have experience with C#). And I've seen a recommendation to use Web.sitemap to have a list of pages of my website. Does this help? Will I be able to use this instead of having links on my web pages somehow? And what about being accessible to Google so my website will be found by searchers – will this help?
The Web.sitemap is not primarily a control to be used for your main navigation; it's meant as a navigational overview for the user and is typically only needed in large sites. It doesn't affect your SEO in any way - Google is more interested in the quality of your content.
A site map (NOT a Web.sitemap) is a list of pages on your site, and used in conjunction with a robots.txt file, CAN help your SEO. You can use the following tool to generate a site map automatically (although you'll nearly always have to hand tweak it as well):
http://www.xml-sitemaps.com/
The normal way to build navigation for a small/medium site is to create a set of links as an unordered set (ul/li) and style them with CSS.
It is possible to use Web.Sitemap as navigation source, though probably not recommended. I've used Web.sitemap driven navigation for a couple of sites I've developed. However, it really only works well if you have a simple site with static content pages. Here's the code I used for example:
<asp:SiteMapDataSource ID="MainMenuDataSource" runat="server"
ShowStartingNode="false" StartingNodeOffset="0"
StartFromCurrentNode="false" />
<ul id="jsddm" style="padding-top:10px;">
<asp:Repeater ID="MainMenuRepeater" DataSourceID="MainMenuDataSource" runat="server">
<ItemTemplate>
<li><%#Container.DataItem.Title%>
<ul>
<asp:Repeater ID="MainMenuRepeater_2" DataSource='<%# Container.DataItem.ChildNodes %>' runat="server">
<ItemTemplate>
<%#Utilities.GetSecondaryMenuItem(Container.DataItem, False)%>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Where Utilities.GetSecondaryMenuItem is just a helper function in our application that uses custom attributes from the sitemap nodes to control the display formatting of the secondary menu.
Links are a fundamental part of any website and there's no reason to avoid them.
A sitemap is just an XML file that defines the site structure, and it's used mainly by search engines to index sites. You can use them for other things too, like crumb trails for example, but they are not a substitute for hyperlinks.
im creating a umbraco plugin, which uses an asp:LinkButton. which looks something like this
<asp:LinkButton ID="ObjectInformationBtn" class="link" runat="server" Text="View Full Details of Item" OnClick="ObjectInformationBtn_Click"></asp:LinkButton>
when I test this plugin locally I get the following result
View Full Details of Item
however when I put the plugin on the website I get a complete different results, which looks like this
<p> </p>
can someone please tell me what is going on.
Are you sure the ascx containing the linkbutton is published to the production website in the usercontrols folder?
Do you have a Macro created that references the User Control that contains the LinkButton?