Membership学习记录

 Membership学习记录

                              ---自定义成员资格用户类型及相关提供程序

一.Web.config文件配制

Membership是基于Forms验证,所以首先得在<system.web>节点下添加Forms验证节点:

         <authentication mode="Forms">

              <forms name="WPFORMAUTH" loginUrl="~/Login.aspx" timeout="90"/>

     </authentication>

此节点的相关属性说明这里就没必要说了,相信大家一看就明白。

接下来依然在<system.web>下添加membership节点:

<membership defaultProvider="MyMembershipProvider">

              <providers>

                   <add name="MyMembershipProvider" type="MyMembershipProvider" requiresQuestionAndAnswer="false" connectionString="DatabaseConnectionString"/>

              </providers>

</membership>

再就是添加 rolemanager节点

<roleManager cacheRolesInCookie="true" defaultProvider="MyRoleProvider" enabled="true">

      <providers>

        <clear/>

        <add connectionStringName="DatabaseConnectionString" applicationName="simple" name="MyRoleProvider" type="MyRoleProvider"/>

      </providers>

</roleManager>

最后就是添加授权节点

<authorization>

        <allow roles="admin,guest"/>

        <deny users="*"/>

 </authorization>

 

二.创建自定义成员资格用户

可以创建一个自定义成员资格用户,方法是创建一个继承 MembershipUser 类的类,然后包括公开其他用户值的属性。此外,还可以向 MembershipUser 类添加方法和事件。调用 Membership 类以创建自定义 MembershipUser 的实例时,将只调用由 MembershipUser 类定义的构造函数。如果 MembershipUser 实现包括其他构造函数重载,则这些构造函数只能由为调用自定义构造函数而专门编写的应用程序代码调用。

代码示例演示一个继承 MembershipUser 类的简单自定义成员资格用户

public class MyMembershipUser:MembershipUser

{

     public MyMembershipUser(string providername,

                                  string username,

                                  object providerUserKey,

                                  string email,

                                  string passwordQuestion,

                                  string comment,

                                  bool isApproved,

                                  bool isLockedOut,

                                  DateTime creationDate,

                                  DateTime lastLoginDate,

                                  DateTime lastActivityDate,

                                  DateTime lastPasswordChangedDate,

                                  DateTime lastLockedOutDate,

                                  string qq) : base(providername,

                                       username,

                                       providerUserKey,

                                       email,

                                       passwordQuestion,

                                       comment,

                                       isApproved,

                                       isLockedOut,

                                       creationDate,

                                       lastLoginDate,

                                       lastActivityDate,

                                       lastPasswordChangedDate,

                                       lastLockedOutDate)

     {

        this._qq = qq;

     }

    private string _qq;

    public string QQ

    {

        get { return _qq; }

        set { _qq = value; }

    }

}

 

三.自定义提供程序

1.       创建自定义成员资格提供程序

创建一个自定义成员资格提供程序,该提供程序支持自定义成员资格用户类型和自定义成员资格数据存储区。可以编写自定义成员资格提供程序的 GetUser CreateUser 方法,以返回自定义成员资格用户类型的对象。可以编写自定义成员资格提供程序的 UpdateUser 方法,以采用自定义成员资格用户类型的对象作为输入。

 

 

 

 

using System;

using System.Web;

using System.Web.Security;

using System.Data;

using System.Data.SqlClient;

 

/// <summary>

///MyMembershipProvider 的摘要说明

/// </summary>

public class MyMembershipProvider:MembershipProvider

{

    private string _connectionString;

 

    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)

    {

        string connStringName = config["connectionString"];//这里去得到那个在web.config节点中配置的数据库连接字符串

        this._connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[connStringName].ConnectionString;

        base.Initialize(name, config);

    }

 

    public override string ApplicationName

    {

        get

        {

            return null;

        }

        set

        {

            //throw new Exception("The method or operation is not implemented.");

        }

    }

 

    public override bool ChangePassword(string username, string oldPassword, string newPassword)

    {

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(this._connectionString);

 

        try

        {

            conn.Open();

            string sql = "UPDATE Users SET Password=@newPassword WHERE UserName=@username AND Password=@oldPassword";

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sql, conn);

            comm.Parameters.AddWithValue("@username", username);

            comm.Parameters.AddWithValue("@oldPassword", oldPassword);

            comm.Parameters.AddWithValue("@newPassword", newPassword);

 

            int result = comm.ExecuteNonQuery();

            if (result > 0)

                return true;

            else

                return false;

        }

        catch

        {

            return false;

        }

        finally

        {

            if (conn.State != ConnectionState.Closed)

                conn.Close();

            conn.Dispose();

        }

    }

 

    public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)

    {

        return false;

    }

 

    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)

    {

        return this.CreateUser(username,password,email,"",out status);

    }

 

 

 

    public  MembershipUser CreateUser(string username, string password, string email, string qq, out MembershipCreateStatus status)

    {

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(this._connectionString);

        try

        {

            conn.Open();

            string sql = "INSERT INTO Users VALUES (@username, @password, @email,@qq)";

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sql, conn);

            comm.Parameters.AddWithValue("@username", username);

            comm.Parameters.AddWithValue("@password", password);

            comm.Parameters.AddWithValue("@email", email);

            comm.Parameters.AddWithValue("@qq", qq);

            comm.ExecuteNonQuery();

            conn.Close();

 

            status = MembershipCreateStatus.Success;

  

            return (MyMembershipUser)GetUser(username, false);

 

        }

        catch (Exception ex)

        {

            status = MembershipCreateStatus.UserRejected;

            return null;

        }

    }

    public override bool DeleteUser(string username, bool deleteAllRelatedData)

    {

        return false;

    }

 

    public override bool EnablePasswordReset

    {

        get

        {

            return false;

        }

    }

 

    public override bool EnablePasswordRetrieval

    {

        get

        {

            return false;

        }

    }

 

    public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)

    {

        totalRecords = 0;

        return null;

    }

 

    public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)

    {

        totalRecords = 0;

        return null;

    }

 

    public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)

    {

        totalRecords = 0;

        return null;

    }

 

    public override int GetNumberOfUsersOnline()

    {

        return 0;

    }

 

    public override string GetPassword(string username, string answer)

    {

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(this._connectionString);

 

        try

        {

            conn.Open();

            string sql = "SELECT password FROM Users WHERE username=@username";

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sql, conn);

            comm.Parameters.AddWithValue("@username", username);

 

            System.Data.SqlClient.SqlDataReader reader = comm.ExecuteReader();

            if (reader.HasRows)

            {

                reader.Read();

                return reader.GetString(0);

            }

            else

                return null;

        }

        catch (Exception ex)

        {

            return null;

        }

        finally

        {

            if (conn.State != ConnectionState.Closed)

                conn.Close();

            conn.Dispose();

        }

    }

 

    public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)

    {

        return null;

    }

 

    public override MembershipUser GetUser(string username, bool userIsOnline)

    {

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(this._connectionString);

 

        try

        {

            conn.Open();

            string sql = "SELECT username,password,qq FROM Users WHERE username=@username";

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sql, conn);

            comm.Parameters.AddWithValue("@username", username);

 

            System.Data.SqlClient.SqlDataReader reader = comm.ExecuteReader();

            if (reader.HasRows)

            {

                reader.Read();

                MembershipUser user = GetUserFromReader(reader);

 

                return user;

            }

            else

                return null;

        }

        catch (Exception ex)

        {

            return null;

        }

        finally

        {

            if (conn.State != ConnectionState.Closed)

                conn.Close();

            conn.Dispose();

        }

    }

 

 

    private MyMembershipUser GetUserFromReader(SqlDataReader reader)

    {

 

        string username = reader.GetString(0);

        string email = reader.GetString(1);

 

        string qq = String.Empty;

        if (reader.GetValue(2) != DBNull.Value)

            qq = reader.GetString(2);

 

        MyMembershipUser u = new MyMembershipUser(this.Name,

                                              username,

                                              string.Empty,

                                              email,

                                              string.Empty,

                                              string.Empty, false, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, qq);

 

        return u;

    }

 

 

 

 

    public override string GetUserNameByEmail(string email)

    {

        return null;

    }

 

    public override int MaxInvalidPasswordAttempts

    {

        get

        {

            return 0;

        }

    }

 

    public override int MinRequiredNonAlphanumericCharacters

    {

        get

        {

            return 0;

        }

    }

 

    public override int PasswordAttemptWindow

    {

        get

        {

            return 0;

        }

    }

 

    public override int MinRequiredPasswordLength

    {

        get

        {

            return 0;

        }

    }

 

    public override MembershipPasswordFormat PasswordFormat

    {

        get

        {

            return MembershipPasswordFormat.Clear;

        }

    }

 

    public override string PasswordStrengthRegularExpression

    {

        get

        {

            return null;

        }

    }

 

    public override bool RequiresQuestionAndAnswer

    {

        get

        {

            return false;

        }

    }

 

    public override bool RequiresUniqueEmail

    {

        get

        {

            return false;

        }

    }

 

    public override string ResetPassword(string username, string answer)

    {

        return null;

    }

 

    public override bool UnlockUser(string userName)

    {

        return false;

    }

 

    public override void UpdateUser(MembershipUser user)

    {

 

    }

 

    public override bool ValidateUser(string username, string password)

    {

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(this._connectionString);

        try

        {

 

            conn.Open();

            string sql = "SELECT * FROM Users WHERE UserName=@username AND Password=@password";

            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sql, conn);

            comm.Parameters.AddWithValue("@username", username);

            comm.Parameters.AddWithValue("@password", password);

 

            System.Data.SqlClient.SqlDataReader reader = comm.ExecuteReader();

 

            if (reader.HasRows)

            {

    

                return true;

            }

            else

            {

                return false;

            }

 

        }

        catch (Exception ex)

        {

            return false;

        }

        finally

        {

            if (conn.State != ConnectionState.Closed)

                conn.Close();

            conn.Dispose();

        }

    }

 

}

 

 

2.       自定义角色提供程序

创建一个继承 System.Web.Security 命名空间中 RoleProvider 抽象类的类。RoleProvider 抽象类继承 System.Configuration.Provider 命名空间的 ProviderBase 抽象类。因此,也必须实现 ProviderBase 类所需的成员。

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Configuration.Provider;

using System.Data.SqlClient;

 

/**//// <summary>

/// MyRole 的摘要说明

/// </summary>

public class MyRoleProvider : RoleProvider

{

    public MyRoleProvider()

    {

        //

        // TODO: 在此处添加构造函数逻辑

        //

    }

 

    string connectionstring = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString.ToString();

 

    public override void AddUsersToRoles(string[] usernames, string[] rolenames)

    {

        foreach (string rolename in rolenames)

        {

            if (!RoleExists(rolename))

            {

                throw new ProviderException("Role name not found.");

            }

        }

 

        foreach (string username in usernames)

        {

            if (username.Contains(","))

            {

                throw new ArgumentException("User names cannot contain commas.");

            }

 

            foreach (string rolename in rolenames)

            {

                if (IsUserInRole(username, rolename))

                {

                    throw new ProviderException("User is already in role.");

                }

            }

        }

 

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("INSERT INTO UsersInRoles (Username,Rolename) Values(@Username, @Rolename)", conn);

 

        SqlParameter userParm = cmd.Parameters.Add("@Username",SqlDbType.VarChar, 255);

        SqlParameter roleParm = cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255);

  

        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 {

                throw e;

            }

 

 

        }

        finally

        {

            conn.Close();

        }

 

    }

 

    public override string ApplicationName

    {

        get

        {

            throw new Exception("The method or operation is not implemented.");

        }

        set

        {

            throw new Exception("The method or operation is not implemented.");

        }

    }

 

    public override void CreateRole(string rolename)

    {

        if (rolename.Contains(","))

        {

            throw new ArgumentException("Role names cannot contain commas.");

        }

 

        if (RoleExists(rolename))

        {

            throw new ProviderException("Role name already exists.");

        }

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("INSERT INTO Roles " +

                " (Rolename) " +

                " Values(@Rolename)", conn);

 

        cmd.Parameters.Add("@Rolename",SqlDbType.VarChar, 255).Value = rolename;

      

        try

        {

            conn.Open();

 

            cmd.ExecuteNonQuery();

        }

        catch (SqlException e)

        {

 

                throw e;

        }

        finally

        {

            conn.Close();

        }

 

    }

 

    public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)

    {

        if (!RoleExists(rolename))

        {

            throw new ProviderException("Role does not exist.");

        }

 

        if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)

        {

            throw new ProviderException("Cannot delete a populated role.");

        }

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("DELETE FROM Roles " +

                " WHERE Rolename =@Rolename ", conn);

 

        cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = rolename;

    

 

 

        SqlCommand cmd2 = new SqlCommand("DELETE FROM UsersInRoles " +

                " WHERE Rolename = @Rolename ", conn);

 

        cmd2.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = rolename;

     

 

        SqlTransaction tran = null;

 

        try

        {

            conn.Open();

            tran = conn.BeginTransaction();

            cmd.Transaction = tran;

            cmd2.Transaction = tran;

 

            cmd2.ExecuteNonQuery();

            cmd.ExecuteNonQuery();

 

            tran.Commit();

        }

        catch (SqlException e)

        {

            try

            {

                tran.Rollback();

            }

            catch {

                throw e;

            }

 

              

        }

        finally

        {

            conn.Close();

        }

 

        return true;

 

    }

 

    public override string[] FindUsersInRole(string rolename, string usernameToMatch)

    {

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("SELECT Username FROM UsersInRoles  " +

                  "WHERE Username LIKE @UsernameSearch AND RoleName =@RoleName", conn);

        cmd.Parameters.Add("@UsernameSearch", SqlDbType.VarChar, 255).Value = usernameToMatch;

        cmd.Parameters.Add("@RoleName", SqlDbType.VarChar, 255).Value = rolename;

 

        string tmpUserNames = "";

        SqlDataReader reader = null;

 

        try

        {

            conn.Open();

 

            reader = cmd.ExecuteReader();

 

            while (reader.Read())

            {

                tmpUserNames += reader.GetString(0) + ",";

            }

        }

        catch (SqlException e)

        {

 

                throw e;

 

        }

        finally

        {

            if (reader != null) { reader.Close(); }

 

            conn.Close();

        }

 

        if (tmpUserNames.Length > 0)

        {

            // Remove trailing comma.

            tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1);

            return tmpUserNames.Split(',');

        }

 

        return new string[0];

 

    }

 

    public override string[] GetAllRoles()

    {

        string tmpRoleNames = "";

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("SELECT Rolename FROM Roles ", conn);

 

 

        SqlDataReader reader = null;

 

        try

        {

            conn.Open();

 

            reader = cmd.ExecuteReader();

 

            while (reader.Read())

            {

                tmpRoleNames += reader.GetString(0) + ",";

            }

        }

        catch (SqlException e)

        {

 

                throw e;

    

        }

        finally

        {

            if (reader != null) { reader.Close(); }

            conn.Close();

        }

 

        if (tmpRoleNames.Length > 0)

        {

            // Remove trailing comma.

            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 UsersInRoles " +

                " WHERE Username = @Username", conn);

 

        cmd.Parameters.Add("@Username", SqlDbType.VarChar, 255).Value = username;

  

        SqlDataReader reader = null;

 

        try

        {

            conn.Open();

 

            reader = cmd.ExecuteReader();

 

            while (reader.Read())

            {

                tmpRoleNames += reader.GetString(0) + ",";

            }

        }

        catch (SqlException e)

        {

 

                throw e;

        }

        finally

        {

            if (reader != null) { reader.Close(); }

            conn.Close();

        }

 

        if (tmpRoleNames.Length > 0)

        {

            // Remove trailing comma.

            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 UsersInRoles " +

                  " WHERE Rolename = @Rolename ", conn);

 

        cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = rolename;

   

        SqlDataReader reader = null;

 

        try

        {

            conn.Open();

 

            reader = cmd.ExecuteReader();

 

            while (reader.Read())

            {

                tmpUserNames += reader.GetString(0) + ",";

            }

        }

        catch (SqlException e)

        {

 

                throw e;

 

        }

        finally

        {

            if (reader != null) { reader.Close(); }

            conn.Close();

        }

 

        if (tmpUserNames.Length > 0)

        {

            // Remove trailing comma.

            tmpUserNames = tmpUserNames.Substring(0, tmpUserNames.Length - 1);

            return tmpUserNames.Split(',');

        }

 

        return new string[0];

 

    }

 

    public override bool IsUserInRole(string username, string rolename)

    {

        bool userIsInRole = false;

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM UsersInRoles " +

                " WHERE Username = @Username AND Rolename = @Rolename", conn);

 

        cmd.Parameters.Add("@Username", SqlDbType.VarChar, 255).Value = username;

        cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = rolename;

 

        try

        {

            conn.Open();

 

            int numRecs = (int)cmd.ExecuteScalar();

 

            if (numRecs > 0)

            {

                userIsInRole = true;

            }

        }

        catch (SqlException e)

        {

                throw e;

        }

        finally

        {

            conn.Close();

        }

 

        return userIsInRole;

 

    }

 

    public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)

    {

        throw new Exception("The method or operation is not implemented.");

    }

 

    public override bool RoleExists(string rolename)

    {

        bool exists = false;

 

        SqlConnection conn = new SqlConnection(connectionstring);

        SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Roles " +

                  " WHERE Rolename = @Rolename ", conn);

 

        cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = rolename;

      

        try

        {

            conn.Open();

 

            int numRecs = (int)cmd.ExecuteScalar();

 

            if (numRecs > 0)

            {

                exists = true;

            }

        }

        catch (SqlException e)

        {

         

                throw e;

        }

        finally

        {

            conn.Close();

        }

 

        return exists;

 

    }

}

 

四.使用方法

1.       验证登录

 protected void Button1_Click(object sender, EventArgs e)

    {

        string username = TextBox2.Text;

        string pwd = TextBox1.Text;

 

        if (Membership.ValidateUser(username, pwd))

            FormsAuthentication.RedirectFromLoginPage(username, true);

        else

            Label1.Text = "login error";

   }

2.       注册

    protected void Button1_Click(object sender, EventArgs e)

    {

        string username = TextBox1.Text;

        string password = TextBox2.Text;

        string email = TextBox3.Text;

        string qq = TextBox4.Text;

        MembershipCreateStatus status;

        ((MyMembershipProvider) Membership.Provider).CreateUser(username,password,email,qq,out status);

}

 

 

3.       权限验证

       User.IsInRole("admin"))

               Response.Write("i'm admin");

4.       角色增加

protected void Button1_Click(object sender, EventArgs e)

    {

        string rolename = TextBox1.Text;

        Roles.CreateRole(rolename);

}

 

5.       角色用户增加

    protected void Button2_Click(object sender, EventArgs e)

    {

        string rolename = DropDownList1.SelectedValue;

        string username = TextBox2.Text;

        Roles.AddUsersToRoles(new string[] { username }, new string[] { rolename });

    }

 

五.附加

用户表:

CREATE TABLE [dbo].[Users] (

         [UserId] [int] IDENTITY (1, 1) NOT NULL ,

         [UserName] [char] (20) COLLATE Chinese_PRC_CI_AS NULL ,

         [Password] [char] (20) COLLATE Chinese_PRC_CI_AS NULL ,

         [Email] [char] (30) COLLATE Chinese_PRC_CI_AS NULL ,

         [QQ] [char] (10) COLLATE Chinese_PRC_CI_AS NULL

) ON [PRIMARY]

 

角色表:

CREATE TABLE [dbo].[Roles] (

         [RoleId] [int] IDENTITY (1, 1) NOT NULL ,

         [Rolename] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL

) ON [PRIMARY]

 

用户角色表:

CREATE TABLE [dbo].[UsersInRoles] (

         [RoleName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,

         [UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL

) ON [PRIMARY]

 

 

转载于:https://www.cnblogs.com/paopaofan/archive/2009/12/03/1616289.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/299611.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

超详细图解!【MySQL进阶篇】MySQL事务和锁

ACID 特性 在关系型数据库管理系统中&#xff0c;一个逻辑工作单元要成为事务&#xff0c;必须满足这 4 个特性&#xff0c;即所谓的 ACID&#xff1a; 原子性&#xff08;Atomicity&#xff09;、一致性&#xff08;Consistency&#xff09;、隔离性&#xff08;Isolation&am…

这道题号称无人能解!300多年来无一人答对,却让这群人这么简单就解出来了?...

全世界只有3.14 % 的人关注了青少年数学之旅最近&#xff0c;一条新闻引起了超模君的注意&#xff1a;“三体问题”或有解了&#xff01;这个蔑视了人类300多年的老顽固&#xff0c;真的要被彻底解决了吗&#xff1f;三体问题到底是什么&#xff1f;三体问题是说&#xff1a;三…

qqsafe病毒 arp网站挂马 原理剖析-786ts.qqsafe-qqservicesyydswfhuw8ysjftwf.org(转载)

昨天小站被挂马了&#xff0c;每次打开都会自动弹出一个对话框&#xff0c;提示正准备安装...&#xff0c;然后就消失。查看页面的源文件会发现在代码的最后面被加上了9 ~0 ]* U9 N2 ^ <body>" z% I9 o( h% [" ? A <iframe src"http://786ts.qqsafe-q…

以软件推动工业进步 -嵌入式学习网站

http://www.cnblogs.com/cubean/archive/2010/04/26/1721035.html 以下内容转自&#xff1a;http://bbs.msembed.com/showtopic-1238.aspx 嵌入式入门篇&#xff1a;什么是嵌入式系统 http://www.helloarm.com/Embedded-Learn/58.htm嵌 入式资深工程师白…

超详细图解!【MySQL进阶篇】MySQL架构原理

MySQL体系架构 MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层。 一、网络连接层 客户端连接器&#xff08;Client Connectors&#xff09;&#xff1a;提供与MySQL服务器建立的支持。目前几乎支持所有主流 的服务端编程技术&#xff0c;例如…

大文件及文件夹上传(续)

上次说到大文件以及文件夹的上传问题&#xff0c;经过两天的研究实现了基本的功能。在安全性配置方面暂时的方案是将网站添加到可信站点中&#xff0c;然后将在装有SDK的机器上配置过的security.config拷贝到客户机的.net framework的配置文件夹&#xff08;%system%\Microsoft…

Dapr 客户端 搭配 WebApiClientCore 玩耍服务调用

使用Dapr 客户端 处理服务调用&#xff0c;需要遵循的他的模式&#xff0c;通常代码是这个样子的&#xff1a;var client DaprClient.CreateInvokeHttpClient(appId: "routing"); var response await client.GetAsJsonAsync($"/accounts/{17}", cancella…

win32下Socket编程(1)

一.win32的socket编程&#xff0c;是socket编程中比较经典也比较基础的一部分&#xff0c;根据传输方式和协议的区别&#xff0c;可以简单的分为TCP传递和UDP传递两种。这篇文章主要是阐述基于TCP的Socket编程。 二.Socket相关API 1.WSAStartup int WSAStartup( __in WORD wVer…

掉入黑洞会怎样?被拉成面条,还是前往另一个宇宙?

全世界只有3.14 % 的人关注了青少年数学之旅○ 黑洞通往何处&#xff1f;现在&#xff0c;你准备好要跳入一个黑洞。如果你能想办法活下来&#xff08;尽管这困难重重&#xff09;&#xff0c;等待着你的是什么呢&#xff1f;如果你想方设法地要回头&#xff0c;最终你会去到哪…

程序员技术练级攻略(转载)

谨以此文献给仍碌碌无为&#xff0c;却渴望成功的Me!,码农路漫漫,需要有一颗坚定的心 本文转载自左耳朵耗子的博文,地址:http://coolshell.cn/articles/4990.html 月光博客6月12日发表了《写给新手程序员的一封信》&#xff0c;翻译自《An open letter to those who want to st…

理论修炼之ETCD,高一致性Key-Value服务提供者中的佼佼者

????欢迎点赞 &#xff1a;???? 收藏 ⭐留言 ???? 如有错误敬请指正&#xff0c;赐人玫瑰&#xff0c;手留余香&#xff01;????本文作者&#xff1a;由webmote 原创&#xff0c;首发于 【掘金】????作者格言&#xff1a;生活在于折腾&#xff0c;当你不折…

反射学习系列3-反射实例应用

反射学习系列目录 反射学习系列1-反射入门 反射学习系列2-特性&#xff08;Attribute&#xff09; 反射学习系列3-反射实例应用 作者 例子这个东西其实挺难弄得,弄个简单的,虽然能说明问题但却容易让人觉得没实用价值,弄个有实用价值却又往往牵扯很多别的技术甚至牵扯很多业务…

怎么向女朋友解释什么叫区块链?

全世界只有3.14 % 的人关注了青少年数学之旅现在最火热的科技和风口&#xff0c;无疑就是“区块链”了。很多投行面试中也总是会被问到 于是&#xff0c;发生了下面的故事……有一对恩爱的男女朋友开始了这样的对话&#xff0c;我们暂且叫他们小明和小花吧。&#xff08;将就点…

遭遇价格欺诈

周末和朋友逛街时&#xff0c;买了副皮手套&#xff0c;店家说帮朋友代卖的&#xff0c;标价318元&#xff0c;打五折&#xff0c;又跟店家讲了下价&#xff0c;虽然店家表现的老大不情愿&#xff0c;但最终还是以130买进。 回家后顺手从网上查了下&#xff0c;淘宝网上才卖75&…

超详细图解!【MySQL进阶篇】MySQL索引原理

索引类型 索引可以提升查询速度&#xff0c;会影响where查询&#xff0c;以及order by排序。MySQL索引类型如下&#xff1a; 从索引存储结构划分&#xff1a;B Tree索引、Hash索引、FULLTEXT全文索引、R Tree索引 从应用层次划分&#xff1a;普通索引、唯一索引、主键索引、复…

Sql plus命令报command not found的解决笔记

Sql plus命令报command not found的解决笔记1.问题描述 环境&#xff1a;linux9, Oracle10g. 在一台装有Oracle10g的Linux机器上&#xff0c;我运行sqlplus命令&#xff0c;报错"command not found",运行别的命令(如:lsnrctl)也同样的错误。初步怀疑是路径问题&#…

ExtJs学习笔记(21)-使用XTemplate结合WCF显示数据

个人认为&#xff0c;XTemplate是ExtJs中最灵活的用来显示数据的组件&#xff0c;有点类似aspx中的Repeater控件&#xff0c;显示数据的模板完全可以由用户以html方式来定制. 先给一个官方的静态示例(稍微改了下)&#xff0c;代码并不复杂&#xff0c;关键的地方&#xff0c;我…

Blazor 路由及导航开发指南

翻译自 Waqas Anwar 2021年4月2日的文章 《A Developer’s Guide To Blazor Routing and Navigation》 [1]检查传入的请求 URL 并将它们导航到对应的视图或页面是每个单页应用程序 (SPA) 框架的基本功能。Blazor Server 和 WebAssembly 应用程序也同样支持使用一些内置组件和服…

超详细图解!【MySQL进阶篇】SQL优化-索引-存储引擎

1. Mysql的体系结构概览 整个MySQL Server由以下组成 Connection Pool : 连接池组件Management Services & Utilities : 管理服务和工具组件SQL Interface : SQL接口组件Parser : 查询分析器组件Optimizer : 优化器组件Caches & Buffers : 缓冲池组件Pluggable Storag…

数据之美

数据是抽象的&#xff0c;尤其是海量数据&#xff0c;人的大脑很难直接对大量数据进行分析并获得印象&#xff0c;然而从另一个角度看&#xff0c;数据也可以异常美丽&#xff0c;人们设计了很多工具&#xff0c;让枯燥的数据图形化&#xff0c;本文介绍了50个数据图形化工具&a…