using System; using System.Data; using System.Configuration; using System.Collections; 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 partial class TestRoleMembership : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write("LOGON_USER = " + Request.ServerVariables["LOGON_USER"] + "<br>"); Response.Write("User.Identity.Name = " + User.Identity.Name + "<br>"); Response.Write("User.Identity.IsAuthenticated = " + User.Identity.IsAuthenticated.ToString() + "<br>"); String[] userNames; string userName; userNames = User.Identity.Name.Split('\\'); userName = userNames[1]; Response.Write("userName = " + userName + "<br>"); Response.Write("Membership.ValidateUser(" + userName +", password) = " + Membership.ValidateUser(userName, "password") + "<br>"); //Response.Write("Roles.IsUserInRole(" + userName + ", AdminPlanning) = " + Roles.IsUserInRole(userName, "AdminPlanning") + "<br>"); //Response.Write("Roles.IsUserInRole(" + userName + ", AdminFinance) = " + Roles.IsUserInRole(userName, "AdminFinance") + "<br>"); MembershipUser user = Membership.GetUser(userName); if (user != null) { string boardPortfolioName = ""; string[] roles = Roles.GetRolesForUser(user.ToString()); Response.Write("<br>Roles that " + user.ToString() + " belongs to:<br>"); Response.Write("<br>Number of roles " + roles.Length + "<br>"); if (roles.Length >= 1) { foreach (string role in roles) { Response.Write(" " + role.ToString() + "<br>"); if (role != "ChairBoardPortfolio") { if (boardPortfolioName == "") { boardPortfolioName = ReadWriteManager.GetUserBoardPortfolio(role); } else { boardPortfolioName = boardPortfolioName + ", " + ReadWriteManager.GetUserBoardPortfolio(role); } //Response.Write(" Found at position " + role.IndexOf(@"Member").ToString() + "<br>"); Response.Write(" Board/Portfolio: " + boardPortfolioName + "<br>"); } } } //else if (roles.Length == 1) //{ // Response.Write(" " + roles[0].ToString() + "<br>"); //} else { Response.Write(" User does not belong to any roles.<br>"); } Response.Write("<br>user.Email = " + user.Email + "<br>"); Response.Write("user.UserName = " + user.UserName + "<br>"); //Response.Write("user.ProviderName = " + user.ProviderName + "<br>"); } else { Response.Write("User does not exist in the membership database.<br>"); } //if (Roles.IsUserInRole(userNames[1], "RoleAdmin")) //{ // GridView1.Visible = true; // DetailsView1.Enabled = true; // GridView1.Enabled = true; // this.form1.Visible = true; //} //else //{ // this.form1.Visible = false; // this.GridView1.Visible = false; //} } }