calvin Posted April 20, 2006 Posted April 20, 2006 (edited) Is anyone know how to populating the menu by user role using SiteMapDataSource in vb code?I found a lot of code use the c#. I'm not familiar with that. "Login Page" <-this is simple login authentication page protected void Button1_Click(object sender, EventArgs e) { string userName = txtUserName.Text; if (userName.Equals("admin")) Response.Redirect("~/Admin/AdminHomePage.aspx"); else if (userName.Equals("user")) Response.Redirect("~/User/UserHomePage.aspx"); } "Class File - Navigation Manager" using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public class NavigationManager { public static SiteMapDataSource GetSiteMapDataSource(string role) { <--How to change to VB code??? string url = String.Empty; if (role.Equals("Admin")) <--- Question 1: How it get this role??, since txtUserName.Text is store in userName url = "~/AdminAdminHomePage.aspx"; else if (role.Equals("User")) url = "~/User/UserHomePage.aspx"; XmlSiteMapProvider xmlSiteMap = new XmlSiteMapProvider(); System.Collections.Specialized.NameValueCollection myCollection = new System.Collections.Specialized.NameValueCollection(1); myCollection.Add("siteMapFile", "Web.sitemap"); xmlSiteMap.Initialize("provider", myCollection); xmlSiteMap.BuildSiteMap(); SiteMapDataSource siteMap = new SiteMapDataSource(); siteMap.StartingNodeUrl = url; siteMap.ShowStartingNode = false; return siteMap; } } Anyone can help me to convert this "VB" code will be more appreciate. Calvin Edited April 20, 2006 by PlausiblyDamp Quote
Cags Posted April 20, 2006 Posted April 20, 2006 My VB isn't perfect, but a conversion of that code is something along the lines of the following (if it's not entirely right it should still save somebody else some time). Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Public Shared Function GetSiteMapDataSource(ByVal role As String) As SiteMapDataSource Dim url As String = String.Empty If (role.Equals("Admin")) Then url = "~/AdminAdminHomePage.aspx" ElseIf (role.Equals("User")) Then url = "~/User/UserHomePage.aspx" End If Dim xmlSiteMap As New XmlSiteMapProvider Dim myCollection As New System.Collections.Specialized.NameValueCollection(1) myCollection.Add("siteMapFile", "Web.sitemap") xmlSiteMap.Initialize("provider", myCollection) xmlSiteMap.BuildSiteMap() Dim siteMap As New SiteMapDataSource siteMap.StartingNodeUrl = url siteMap.ShowStartingNode = False Return siteMap End Function Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.