/* 数据表SQL脚本
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_UsersInRoles_Roles]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[UsersInRoles] DROP CONSTRAINT FK_UsersInRoles_Roles
GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UsersInRoles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UsersInRoles]
GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Roles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Roles]
GO CREATE TABLE [dbo].[Roles] (
[Rolename] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[ApplicationName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO CREATE TABLE [dbo].[UsersInRoles] (
[Username] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Rolename] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[ApplicationName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO ALTER TABLE [dbo].[Roles] WITH NOCHECK ADD
CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED
(
[Rolename],
[ApplicationName]
) ON [PRIMARY]
GO ALTER TABLE [dbo].[UsersInRoles] WITH NOCHECK ADD
CONSTRAINT [PK_UsersInRoles] PRIMARY KEY CLUSTERED
(
[Username],
[Rolename],
[ApplicationName]
) ON [PRIMARY]
GO ALTER TABLE [dbo].[UsersInRoles] ADD
CONSTRAINT [FK_UsersInRoles_Roles] FOREIGN KEY
(
[Rolename],
[ApplicationName]
) REFERENCES [dbo].[Roles] (
[Rolename],
[ApplicationName]
) ON DELETE CASCADE ON UPDATE CASCADE
GO
*/ using System.Web.Security;
using System.Configuration.Provider;
using System.Collections.Specialized;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;
using System.Web;
using System.Globalization;
using System.Web.Configuration; namespace MyProvider
{
///
/// 角色提供程序
///
public class MyRoleProvider : RoleProvider
{
private string rolesTable = "Roles";
private string usersInRolesTable = "UsersInRoles"; private string eventSource = "SqlRoleProvider";
private string eventLog = "Application";
private string exceptionMessage = "一个异常被抛出,请查看事件日志。"; ///
/// 连接字符串
///
private string connectionString;
public string ConnectionString
{
get { return connectionString; }
set { connectionString = value; }
} //
// 如果false,有异常的话就抛出。如果true,有异常就写入日志。
//
private bool pWriteExceptionsToEventLog = false;
public bool WriteExceptionsToEventLog
{
get { return pWriteExceptionsToEventLog; }
set { pWriteExceptionsToEventLog = value; }
} //
// System.Web.Security.RoleProvider properties.
// 使用配置文件 (Web.config) 中指定的角色信息的应用程序的名称。
private string pApplicationName;
public override string ApplicationName
{
get { return pApplicationName; }
set { pApplicationName = value; }
} ///
/// 构造函数
///
public MyRoleProvider()
{ } ///
/// 初始化角色提供程序
/// 接受提供程序的名称和配置设置的 NameValueCollection 作为输入。用于设置提供程序实例的属性值,其中包括特定于实现的值和配置文件(Machine.config 或 Web.config)中指定的选项。
///
/// 提供程序的名称
/// 配置设置
public override void Initialize(string name, NameValueCollection config)
{
//
// Initialize values from web.config.
//
if (config == null)
throw new ArgumentNullException("config"); if (name == null || name.Length == 0)
name = "MyRoleProvider"; if (String.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "LuoTong.MyRoleProvider");
} // Initialize the abstract base class.
base.Initialize(name, config); if (config["applicationName"] == null || config["applicationName"].Trim() == "")
pApplicationName = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
else
pApplicationName = config["applicationName"]; if (config["writeExceptionsToEventLog"] != null)
{
if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
pWriteExceptionsToEventLog = true;
} //
// Initialize SQLConnection.
//
if (string.IsNullOrEmpty(config["connectionStringName"]))
throw new ArgumentNullException("角色提供程序的数据库连接字符串未初始化"); ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
connectionString = css.ConnectionString;
} ///
/// 用户添加到角色
///
/// 一个用户名
/// 一个角色名
public void AddUserToRole(string username, string rolename)
{
if (!RoleExists(rolename))
throw new ProviderException("没有此角色。"); if (rolename.IndexOf(',') > 0)
throw new ArgumentException("角色名中不能包含逗号。"); if (username.IndexOf(',') > 0)
throw new ArgumentException("用户名中不能包含逗号。"); if (IsUserInRole(username, rolename))
throw new ProviderException("用户已经在此角色中。"); SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO [" + usersInRolesTable + "]" + " (Username, Rolename, ApplicationName) " + " Values(@Username, @Rolename, @ApplicationName)", conn); cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20).Value = username;
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "AddUserToRole");
else
throw e;
}
finally
{
conn.Close();
}
} ///
/// 角色提供程序.多个用户添加到多个角色
/// 接受用户名列表和角色名列表作为输入,然后将指定的用户与在已配置的 ApplicationName 的数据源中指定的角色关联。
///
/// 用户名列表
/// 角色名列表
public override void AddUsersToRoles(string[] usernames, string[] rolenames)
{
foreach (string rolename in rolenames)
{
if (!RoleExists(rolename))
throw new ProviderException("没有此角色。"); if (rolename.IndexOf(',') > 0)
throw new ArgumentException("角色名中不能包含逗号。");
} foreach (string username in usernames)
{
if (username.IndexOf(',') > 0)
throw new ArgumentException("用户名中不能包含逗号。"); foreach (string rolename in rolenames)
{
if (IsUserInRole(username, rolename))
throw new ProviderException("用户已经在此角色中。");
}
} SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO [" + usersInRolesTable + "]" + " (Username, Rolename, ApplicationName) " + " Values(@Username, @Rolename, @ApplicationName)", conn);
SqlParameter userParm = cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20);
SqlParameter roleParm = cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; SqlTransaction tran = null; try
{
conn.Open();
tran = conn.BeginTransaction();
cmd.Transaction = tran; foreach (string username in usernames)
{
foreach (string rolename in rolenames)
{
userParm.Value = username;
roleParm.Value = rolename;
cmd.ExecuteNonQuery();
}
} tran.Commit();
}
catch (SqlException e)
{
try
{
tran.Rollback();
}
catch { } if (WriteExceptionsToEventLog)
WriteToEventLog(e, "AddUsersToRoles");
else
throw e;
}
finally
{
conn.Close();
}
} ///
/// 角色提供程序.创建角色
/// 接受角色名作为输入,并将指定的角色添加到已配置的 ApplicationName 的数据源中。
///
/// 角色名
public override void CreateRole(string rolename)
{
if (rolename.IndexOf(',') > 0)
throw new ArgumentException("角色名中不能包含逗号。"); if (RoleExists(rolename))
throw new ProviderException("角色名已经存在。"); SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO [" + rolesTable + "]" + " (Rolename, ApplicationName) " + " Values(@Rolename, @ApplicationName)", conn);
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "CreateRole");
else
throw e;
}
finally
{
conn.Close();
}
} ///
/// 角色提供程序.删除角色
/// 接受角色名以及一个指示如果仍有用户与该角色关联时是否引发异常的布尔值作为输入。
///
/// 角色名
/// 如果有用户与此角色关联是否引发异常
/// 是否删除成功
public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
{
if (!RoleExists(rolename))
throw new ProviderException("角色不存在。"); if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)
throw new ProviderException("不能删除含有用户的角色。"); SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("DELETE FROM [" + rolesTable + "]" + " WHERE Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
{
WriteToEventLog(e, "DeleteRole");
return false;
}
else
{
throw e;
}
}
finally
{
conn.Close();
} return true;
} ///
/// 角色提供程序.返回所有角色名
/// 从数据源返回角色名的列表。
///
/// 角色名列表
public override string[] GetAllRoles()
{
string tmpRoleNames = ""; SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT Rolename FROM [" + rolesTable + "]" + " WHERE ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; SqlDataReader reader = null; try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
// 用逗号将多个用户名分开。
tmpRoleNames += reader.GetString(0) + ",";
}
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "GetAllRoles");
else
throw e;
}
finally
{
if (reader != null) { reader.Close(); }
conn.Close();
} if (tmpRoleNames.Length > 0)
{
// 删除最后一个多余的逗号。
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1);
return tmpRoleNames.Split(',');
}
return new string[0];
} ///
/// 角色提供程序.根据用户名返回角色
/// 接受用户名作为输入,并从数据源返回与指定的用户关联的角色名。
///
///
///
public override string[] GetRolesForUser(string username)
{
string tmpRoleNames = ""; SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT Rolename FROM [" + usersInRolesTable + "]" + " WHERE Username = @Username AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20).Value = username;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; SqlDataReader reader = null; try
{
conn.Open();
reader = cmd.ExecuteReader(); while (reader.Read())
{
// 将角色名用逗号分开。
tmpRoleNames += reader.GetString(0) + ",";
}
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "GetRolesForUser");
else
throw e;
}
finally
{
if (reader != null) { reader.Close(); }
conn.Close();
} if (tmpRoleNames.Length > 0)
{
// 删除最后一个多余的逗号。
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1);
return tmpRoleNames.Split(',');
} return new string[0];
} ///
/// 角色提供程序.返回角色中所有用户。
/// 接受角色名作为输入,并从数据源返回与角色关联的用户名。
///
/// 角色名
/// 用户名列表
public override string[] GetUsersInRole(string rolename)
{
string tmpUserNames = ""; SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT Username FROM [" + usersInRolesTable + "]" + " WHERE Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; SqlDataReader reader = null; try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
// 用逗号将多个用户名分开。
tmpUserNames += reader.GetString(0) + ",";
}
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "GetUsersInRole");
else
throw e;
}
finally
{
if (reader != null) { reader.Close(); }
conn.Close();
} if (tmpUserNames.Length > 0)
{
// 删除最后一个多余的逗号。
tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1);
return tmpUserNames.Split(',');
}
return new string[0];
} ///
/// 角色提供程序.叛断此用户是否属于此角色
/// 接受用户名和角色名作为输入,并确定当前登录用户是否与已配置的 ApplicationName 的数据源中的角色关联。
///
/// 用户名
/// 角色名
/// 是否有关联
public override bool IsUserInRole(string username, string rolename)
{
bool userIsInRole = false; SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [" + usersInRolesTable + "]" + " WHERE Username = @Username AND Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20).Value = username;
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; try
{
conn.Open();
int numRecs = (int)cmd.ExecuteScalar(); if (numRecs > 0)
userIsInRole = true;
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "IsUserInRole");
else
throw e;
}
finally
{
conn.Close();
} return userIsInRole;
} ///
/// 删除用户和角色的关联
///
/// 用户名
/// 角色名
public void RemoveUserFromRole(string username, string rolename)
{
if (!RoleExists(rolename))
throw new ProviderException("角色名不存在。"); if (!IsUserInRole(username, rolename))
throw new ProviderException("用户不在角色中。"); SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("DELETE FROM [" + usersInRolesTable + "]" + " WHERE Username = @Username AND Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20).Value = username;
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "RemoveUserFromRole");
else
throw e;
}
finally
{
conn.Close();
}
} ///
/// 角色提供程序.删除用户和角色的关联
/// 接受用户名列表和角色名列表作为输入,然后删除指定用户与在已配置的 ApplicationName 的数据源中的指定角色的关联。
///
/// 用户名列表
/// 角色名列表
public override void RemoveUsersFromRoles(string[] usernames, string[] rolenames)
{
foreach (string rolename in rolenames)
{
if (!RoleExists(rolename))
throw new ProviderException("角色名不存在。");
} foreach (string username in usernames)
{
foreach (string rolename in rolenames)
{
if (!IsUserInRole(username, rolename))
throw new ProviderException("用户不在角色中。");
}
} SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("DELETE FROM [" + usersInRolesTable + "]" + " WHERE Username = @Username AND Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
SqlParameter userParm = cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 20);
SqlParameter roleParm = cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20);
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; SqlTransaction tran = null; try
{
conn.Open();
tran = conn.BeginTransaction();
cmd.Transaction = tran; foreach (string username in usernames)
{
foreach (string rolename in rolenames)
{
userParm.Value = username;
roleParm.Value = rolename;
cmd.ExecuteNonQuery();
}
} tran.Commit();
}
catch (SqlException e)
{
try
{
tran.Rollback();
}
catch { } if (WriteExceptionsToEventLog)
WriteToEventLog(e, "RemoveUsersFromRoles");
else
throw e;
}
finally
{
conn.Close();
}
} ///
/// 角色提供程序.判断是否存在此角色
/// 接受角色名作为输入,并确定在已配置的 ApplicationName 的数据源中是否存在该角色名。
///
/// 角色名
/// 是否存在
public override bool RoleExists(string rolename)
{
bool exists = false; SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [" + rolesTable + "]" + " WHERE Rolename = @Rolename AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@Rolename", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = ApplicationName; try
{
conn.Open();
int numRecs = (int)cmd.ExecuteScalar(); if (numRecs > 0)
exists = true;
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "RoleExists");
else
throw e;
}
finally
{
conn.Close();
} return exists;
} ///
/// 角色提供程序.在角色中查找用户
/// 接受角色名和要搜索的用户名作为输入,并返回角色中的用户列表
///
/// 角色名
/// 要搜索的用户名
/// 用户列表
public override string[] FindUsersInRole(string rolename, string usernameToMatch)
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("SELECT Username FROM [" + usersInRolesTable + "] " + "WHERE Username LIKE @UsernameSearch AND RoleName = @RoleName AND ApplicationName = @ApplicationName", conn);
cmd.Parameters.Add("@UsernameSearch", SqlDbType.NVarChar, 20).Value = usernameToMatch;
cmd.Parameters.Add("@RoleName", SqlDbType.NVarChar, 20).Value = rolename;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 20).Value = pApplicationName; string tmpUserNames = "";
SqlDataReader reader = null; try
{
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
// 将多个用户名用逗号分开。
tmpUserNames += reader.GetString(0) + ",";
}
}
catch (SqlException e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "FindUsersInRole");
else
throw e;
}
finally
{
if (reader != null) { reader.Close(); }
conn.Close();
}
if (tmpUserNames.Length > 0)
{
// 删除最后一个多余的逗号。
tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1);
return tmpUserNames.Split(',');
}
return new string[0];
} ///
/// 写入事件日志
///
/// 异常
/// 操作
private void WriteToEventLog(SqlException e, string action)
{
EventLog log = new EventLog();
log.Source = eventSource;
log.Log = eventLog; string message = exceptionMessage + "\n\n";
message += "操作:" + action + "\n\n";
message += "异常:" + e.ToString(); log.WriteEntry(message);
}
}
}
使用时,在web.config中添加如下配置:

<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" defaultProvider="MyRoleProvider">
<providers>
<clear />
<add applicationName="你的站点名" name="MyRoleProvider" type="MyRoleProvider" connectionStringName="ConnectionString1" writeExceptionsToEventLog="false" />
providers>
roleManager>
然后在你的代码中就可以直接使用Roles类了,静态的,很方便。比如添加一个用户到一个组中:Roles.AddUserToRole("张三", "管理员");

MVC中重写RoleProvider角色管理的更多相关文章

  1. MVC中的一般权限管理

    权限管理,一般指根据系统设置的安全规则或者安全策略,用户可以访问而且只能访问自己被授权的资源,不多不少.权限管理几乎出现在任何系统里面,只要有用户和密码的系统.权限管理还是比较复杂的,有的固定到某个模 ...

  2. 七天学会ASP.NET MVC (五)——Layout页面使用和用户角色管理

    系列文章 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 七天学会ASP.NET MVC (二)——ASP.NET MVC 数据传递 七天学会ASP.NET MVC (三)— ...

  3. 七天学会ASP.NET MVC (五)——Layout页面使用和用户角色管理 【转】

    http://www.cnblogs.com/powertoolsteam/p/MVC_five.html 系列文章 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 七天学会 ...

  4. MVc Forms Membership rolemanage 角色权限验证管理

    Forms  登录验证Membership 权限验证rolemanage 角色管理 以往的项目中只有单纯的Forms 验证今天想把这三个结合到mvc 中发现要导入aspnet_ 相关表,但是有个问题验 ...

  5. asp.net mvc 中 一种简单的 URL 重写

    asp.net mvc 中 一种简单的 URL 重写 Intro 在项目中想增加一个公告的功能,但是又不想直接用默认带的那种路由,感觉好low逼,想弄成那种伪静态化的路由 (别问我为什么不直接静态化, ...

  6. Tomcat学习笔记 - 错误日志 - NetBeans配置tomcat出错情况总结 -- 尚未授予访问 Tomcat 服务器的权限。请在服务器管理器的 Tomcat 定制器中设置 "manager-script" 角色的正确用户名和口令。 有关详细信息, 请查看服务器日志。

    错误描述: 发布时控制台出现: 部署错误: 尚未授予访问 Tomcat 服务器的权限.请在服务器管理器的 Tomcat 定制器中设置 "manager-script" 角色的正确用 ...

  7. 在ASP.NET MVC中使用区域来方便管理controller和view

    在ASP.NET MVC中使用区域来方便管理controller和view 在mvc架构中,一般在controllers和views中写所有控制器和视图, 太多控制器时候,为了方便管理,想要将关于pe ...

  8. ASP.NET MVC 认证模块报错:“System.Configuration.Provider.ProviderException: 未启用角色管理器功能“

    新建MVC4项目的时候 选 Internet 应用程序的话,出来的示例项目就自带了默认的登录认证等功能.如果选空或者基本,就没有. 如果没有,现在又想加进去,怎么办呢? 抄啊.将示例项目的代码原原本本 ...

  9. roleManager与角色管理授权

    总览地址 https://msdn.microsoft.com/zh-cn/library/9ab2fxh0.aspx 其中基本概述是第一篇:了解角色管理 来自 <https://msdn.mi ...

随机推荐

  1. 软工+C(2017第1期) 题目设计、点评和评分

    // 下一篇:分数和checklist 如何设计题目 教学中的一个问题是老师出题太简单了,题目设计一开始上来就不紧凑,我认为一个好的课程应该上来就给你紧凑感,而不是先上来"轻松2-3周&qu ...

  2. 201521123107 《Java程序设计》第7周学习总结

    第7周作业-集合 1.本周学习总结 2.书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 源代码如下: public boolean contains( ...

  3. 第1周-java作业总结与建议

    1. 本周作业简评与建议 存在的问题: 这周的作业普遍存在一个格式混乱的问题.请认真学习Markdown,我们后面的作业都要使用Markdown.Markdown学习请参考http://group.c ...

  4. java课程设计--We Talk(201521123061)

    java课程设计--We Talk(201521123061) 团队博客链接:http://www.cnblogs.com/slickghost/ 数据库 一.通过Dao模式建立与数据库的连接 1.数 ...

  5. 201521123117 《Java程序设计》第7周学习总结

    1. 本周学习总结 2.书面作业 Q1.ArrayList代码分析 1.解释ArrayList的contains源代码 源代码: //contains()方法 public boolean conta ...

  6. 201521123045 《Java程序设计》第7周学习总结

    Java 第七周总结 1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Obj ...

  7. 201521123050《Java程序设计》第2周学习总结

    本周学习总结 (1)掌握各种数据类型的使用 基本类型 整数类型(byte,short,int,long,char) 浮点类型(float,double) boolean类型(true, false) ...

  8. 201521123100 《java程序设计》第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  9. 搭建连接MySql的三层架构的ASP.NetCore2.0的WebApi

    里我们用三层架构搭建一个连接MySql的ASP.netCore模板的WebApi项目 首先添加WebApi项目(ASP.NetCore版本) 右键解决方案>新建项目> 选择Web>A ...

  10. org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably du

    如果出现类似下面的错误,原因就是JDK版本太高了,我换成1.7就没事了 Caused by: org.springframework.core.NestedIOException: ASM Class ...