I have a sitemap that has a link for when a user is not logged in, but when they do login, the link should change, for example, nonmember.aspx should change to member.aspx. This sitemap is tied to an asp:menu. Does anyone know how to do this?
+1
A:
A simple solution is to have two nodes in your sitemap.
One node shows up for Non-authenticated users but not for logged in ones.
One node shows up for Authenticated users with the security access
I believe you can set this up quite simply.
The end result is the same as changing the link but it's easier to maintain.
To add to this:
<siteMap>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Member.aspx" title="Home" roles="SpecialPeople">
<siteMapNode url="~/Nonmember.aspx" title="Site Map" roles="HideForUsers" >
</siteMapNode>
</siteMap>
So, you set up a rule that Denies Access to the "HideForMembers" role to authenticated users. It's something like that. ASP.Net will take the first rule it finds a match, so you should be able to accomplish it this way.
Otherwise, you could do a Menu_OnDataBound and look for the node:
Protected Sub menMainDataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim myPage As New Page
Dim myPrincipal As IPrincipal
Dim colNodes As New Collection
myPrincipal = myPage.User
If myPrincipal.Identity.IsAuthenticated = True Then
Dim menNode As MenuItem
For Each menNode In menMain.Items
Select Case menNode.Value.ToString
Case "Products"
colNodes.Add(menNode)
Case "Contact Us"
colNodes.Add(menNode)
Case "About Us"
colNodes.Add(menNode)
Case "Links"
colNodes.Add(menNode)
End Select
Next
For Each menNode In colNodes
menMain.Items.Remove(menNode)
Next
End If
Catch ex As Exception
End Try
End Sub
Atømix
2009-07-09 22:33:02
Do you have an example?
Xaisoft
2009-07-09 22:40:29
Not an example, but here's another approach:http://forums.asp.net/p/1161879/1922913.aspx#1922913
Atømix
2009-07-09 22:48:58
This works, but Nonmember and member are pretty much the same page, so if a member logs in, they will see both. Do you know if there is a way to hide the nonmember page to members, so they will not see duplicates?
Xaisoft
2009-07-09 23:10:04
Sure, you should be able to set a rule to "Deny" access to logged in users.
Atømix
2009-07-09 23:37:34
I actually ended up using the web.config instead of the sitemap. Thanks for the direction.
Xaisoft
2009-07-10 16:06:56
+1
A:
The below is the web.config code you're looking for:
<location path="Registration.aspx">
<system.web>
<authorization>
<allow users="?" />
<deny users="*" />
</authorization>
</system.web>
</location>
knight0323
2009-08-23 05:13:06