Hello Team,
I am Stuck In my Application please help me Out.
I have Developed Many web form pages in my application where i have created 4 table in my database UserMaster, RoleMaster, PageMaster and Permissioin table based on that when i have login in with admin id then menu is showing and also when i login with any userid then also all menu is showing. I want when Admin will login then show also admin menu and if user will login then hide the admin menu. I have developed the master page where I am showing the menu by using menu control and using sitemap but i try according but it is not working please help me out.
I am refer your article
But i didn't get idea how to implement this because i didn't want to use store procedure here as i am using permission table based of that please help me how can I get solution of it in asp.net C#
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
<authentication mode="Forms">
<forms defaultUrl="Home.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="20">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<siteMap enabled ="true" defaultProvider="SiteMap">
<providers>
<add name="SiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/Web.sitemap" securityTrimmingEnabled="true" />
</providers>
</siteMap>
</system.web>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="~/Home.aspx" title="Home" description="Home Page" roles="*"/>
<siteMapNode title="Admin" description="Admin Management Page" roles="Admin">
<siteMapNode url="~/Admin/RoleMaster.aspx" title="Role Master" description="Role Master Page"></siteMapNode>
<siteMapNode url="~/Admin/UserToRole.aspx" title="UTR Master" description="User to Role Page"></siteMapNode>
</siteMapNode>
<siteMapNode url="~/CarsList.aspx" title="CarList" description="Car List Pages" roles="*"></siteMapNode>
<siteMapNode url="~/Services.aspx" title="Services" description="Services Pages" roles="*"></siteMapNode>
<siteMapNode url="~/Viewcars.aspx" title="Viewcars" description="ViewCars Pages" roles="*"></siteMapNode>
<siteMapNode url="~/AboutUs.aspx" title="AboutUs" description="About Us Pages" roles="*"></siteMapNode>
<siteMapNode url="~/Login.aspx" title="Login" description="Login Pages" roles="*" />
<siteMapNode url="~/UserProfile.aspx" title="UserProfile" description="UserProfile Pages" roles="*" />
</siteMapNode>
</siteMap>
protected void OnLogin_Click(object sender, EventArgs e)
{
int userid = 0;
string roles = string.Empty;
string mixedPassword = MixStrings(txtUsername.Text, "MAkv2SPBnI99212" + txtPassword.Text);
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("select u.UserId,u.Password,r.roleName as Roles from UserRegTable u inner join User_tblRole r on r.roleId=u.RoleId WHERE Username=@UserName", con))
{
cmd.Parameters.AddWithValue("@UserName", txtUsername.Text.Trim());
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
string storePassword = sdr["Password"].ToString();
if (storePassword == mixedPassword)
{
userid = Convert.ToInt32(sdr["UserId"]);
roles = sdr["Roles"].ToString();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtUsername.Text.Trim(), DateTime.Now, DateTime.Now.AddMinutes(2880), chkRemember.Checked, roles, FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text.Trim(), chkRemember.Checked));
}
con.Close();
}
}
}
}