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"] + "
"); Response.Write("User.Identity.Name = " + User.Identity.Name + "
"); Response.Write("User.Identity.IsAuthenticated = " + User.Identity.IsAuthenticated.ToString() + "
"); String[] userNames; string userName; userNames = User.Identity.Name.Split('\\'); userName = userNames[1]; Response.Write("userName = " + userName + "
"); Response.Write("Membership.ValidateUser(" + userName +", password) = " + Membership.ValidateUser(userName, "password") + "
"); //Response.Write("Roles.IsUserInRole(" + userName + ", AdminPlanning) = " + Roles.IsUserInRole(userName, "AdminPlanning") + "
"); //Response.Write("Roles.IsUserInRole(" + userName + ", AdminFinance) = " + Roles.IsUserInRole(userName, "AdminFinance") + "
"); MembershipUser user = Membership.GetUser(userName); if (user != null) { string boardPortfolioName = ""; string[] roles = Roles.GetRolesForUser(user.ToString()); Response.Write("
Roles that " + user.ToString() + " belongs to:
"); Response.Write("
Number of roles " + roles.Length + "
"); if (roles.Length >= 1) { foreach (string role in roles) { Response.Write("    " + role.ToString() + "
"); if (role != "ChairBoardPortfolio") { if (boardPortfolioName == "") { boardPortfolioName = ReadWriteManager.GetUserBoardPortfolio(role); } else { boardPortfolioName = boardPortfolioName + ", " + ReadWriteManager.GetUserBoardPortfolio(role); } //Response.Write("    Found at position " + role.IndexOf(@"Member").ToString() + "
"); Response.Write("    Board/Portfolio: " + boardPortfolioName + "
"); } } } //else if (roles.Length == 1) //{ // Response.Write("    " + roles[0].ToString() + "
"); //} else { Response.Write("    User does not belong to any roles.
"); } Response.Write("
user.Email = " + user.Email + "
"); Response.Write("user.UserName = " + user.UserName + "
"); //Response.Write("user.ProviderName = " + user.ProviderName + "
"); } else { Response.Write("User does not exist in the membership database.
"); } //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; //} } }