[英]custom role provider namespace missing
我正在嘗試編寫自己的角色提供程序,但是它說缺少名稱空間,我在做什么錯。 我在C#MVC Visual Studio 2012中編碼。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security.RoleProvider; //this gave me an error
using MyProject.Models;
namespace MyProject.Controllers
{
public class MyRoleProvider : RoleProvider
{
//
// GET: /RoleProvider/
private DefaultConnection db = new DefaultConnection();
public ActionResult Index()
{
return View();
}
public override bool IsUserInRole(string username, string roleName)
{
// Return status defaults to false
bool ret = false;
if (RoleExists(roleName))
{
{
int c = (from m in db.Users
where m.userid == username &&
m.role == roleName
select m).Count();
if (c > 0)
ret = true;
}
}
return ret;
}
public override bool RoleExists(string roleName)
{
bool ret = false;
// If the specified role doesn't exist
if (!GetAllRoles().Contains(roleName))
ret = true;
return ret;
}
public override string[] GetAllRoles()
{
string[] roles = null;
roles = (from roleadmin in db.Users
select roleadmin.userid).ToArray();
return roles;
}
}
}
只需使用
using System.Web.Security;
而不是將類名添加到using中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.