PDA

View Full Version : مبتدی: کنترل منوها با role دیتابیس؟؟



ab_ir_007
سه شنبه 16 فروردین 1390, 20:51 عصر
با سلام
دوستان اگر ممکنه در مورد کنترل منوها بوسیله role توضیح بدین مشکل اینجاست که من مطالب زیادی دیدم که نشون میده چطور با WSATجداول مورد نیاز رو بسازیم و بعد از همونجا رولها رو بسازیم و از طریق کلاس Authentication فقط کافیه رول رو از تو منو چک کنیم ولی من قصد دارم دیتابیسی که دارم را تغییر ندم (یک سری جدولدست ساز خصوصی که یکیشون مربوط به اطلاعات مورد نیاز کاربران باشد) و از همون جداولی که وجود داره رول رو واکشی کنم و بعدش توی منو بوسیله SiteMapNode رولها رو بررسی و اجازه دسترسی بدم اگر ممکنه توضیح بدین چطور این کارها رو انجام بدم , بیشترین قسمتی که مشکل دارم در مورد کلاسی هست که این کارو انجام میده میخوام یه جوری شبیه WSAT باشه که حتی بشه بعدابراحتی روی پروفایلها هم کار کرد.

komeil64
سه شنبه 16 فروردین 1390, 22:37 عصر
از کلاس roleprovider استفاده کن

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;


namespace WebApplication4.Classes
{
public class eShopRoleProvider : RoleProvider
{
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}

public override string ApplicationName
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override void CreateRole(string roleName)
{
throw new NotImplementedException();
}

public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
throw new NotImplementedException();
}

public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
throw new NotImplementedException();
}

public override string[] GetAllRoles()
{
throw new NotImplementedException();
}

public override string[] GetRolesForUser(string username)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrin gs["books"].ToString());
string[] roles = new string[1];
try
{
con.Open();
string sql = "Select roll from tbl_user Where user_name = @user_name";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add(new SqlParameter("user_name", username));


SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
roles[0] = reader["roll"].ToString();
}

}
catch
{

}
finally
{
con.Close();
}
return roles;
}

public override string[] GetUsersInRole(string roleName)
{
throw new NotImplementedException();
}

public override bool IsUserInRole(string username, string roleName)
{
throw new NotImplementedException();
}

public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}

public override bool RoleExists(string roleName)
{
throw new NotImplementedException();
}
}
}