سلام
من در پروژه asp.net MVC می خواهم احراز هویت را پیاده سازی کنم
جداول users و Roles رو خودم در دیتابیس ساختم
کدهای زیر را در وب کانفیگ گذاشتم
<add key="enableSimpleMembership" value="false" />
<add key="autoFormsAuthentication" value="false" />
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login"
defaultUrl="~/Home/Index"
timeout="2880"
slidingExpiration="true"/>
</authentication>
<roleManager enabled="true" defaultProvider="MyProvider">
<providers>
<clear/>
<add name="MyProvider" type="eShopMvc.Classes.eShopMvcRoleProvider"/>
</providers>
</roleManager>
<system.web/>
کلاس eShopMvcRoleProvider رو هم به پروژه اضافه کردم که محتویات زیر داخلش هست
public class eShopMvcRoleProvider: RoleProvider
{
StoreSoftwareEntities db = new StoreSoftwareEntities();
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)
{
string[] roles =
db.Stores.Include("Roles")
.Where(u => u.Username == username)
.Select(u => u.Roles.RoleInSystem)
.ToArray();
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();
}
}
بالای اکشن های کنترل نیز نوشته ام [Authorize(Roles = "administrator")]
اما وقتی ویو مربوط به اکشن را باز می کنم با ارور زیر مواجه می شوم
HTTP Error 401.0 - Unauthorized
You do not have permission to view this directory or page.