The general permission management system records a problem in the logon log.

Source: Internet
Author: User

The general permission management system records a problem in the logon log.

Recently, a project was developed using the general permission management system. The database is MSSQL. An error occurs during logon and the log is recorded.

The log is recorded every time you log on, that is, an error occurs when you log on.

First put the error

It can be seen that it is related to the ID of the BaseLoginLog table that records the logon log. Open this table

If the table ID is nvarchar (50), query the data of the table as follows:

As you can see, IDS actually store GUID-type data. Then I debug the underlying code and find three places:

1 // <summary> 2 // log logon log 3 // </summary> 4 // <param name = "systemCode"> System Code </param> 5 // <param name = "userId"> User ID </param> 6 // <param name = "userName"> logon user name </param> 7 // <param name = "ipAddress"> ip address </param> 8 // <param name = "macAddress"> MAC address </param> 9 /// <param name = "loginStatus "> logon result </param> 10 // <returns> </returns> 11 public static string AddLog (string systemCode, string userId, string userName, string ipAddress, string macAddress, string loginStatus) 12 {13 BaseLoginLogEntity entity = new BaseLoginLogEntity (); 14 entity. systemCode = systemCode; 15 entity. userId = userId; 16 entity. userName = userName; 17 entity. IPAddress = ipAddress; 18 entity. MACAddress = macAddress; 19 entity. loginStatus = loginStatus; 20 entity. createOn = DateTime. now; 21 string tableName = BaseLoginLogEntity. tableName; 22 if (BaseSystemInfo. businessDbType = CurrentDbType. oracle) 23 {24 tableName + = DateTime. now. toString ("yyyyMM"); 25} 26 BaseLoginLogManager loginLogManager = new BaseLoginLogManager (tableName); 27 return loginLogManager. add (entity, true, false); 28}

 

1 /// <summary> 2 /// Add. manual intervention is allowed here, improve program performance 3 // </summary> 4 // <param name = "entity"> entity </param> 5 // <param name = "identity"> auto increment mode, whether the table's primary key adopts an auto-increment policy </param> 6 // <param name = "returnId"> returns the primary key. If no program is returned, the auto-increment policy is enabled, it is mainly used to optimize the batch insertion of data in the primary table </param> 7 // <returns> Primary Key </returns> 8 public string Add (BaseLoginLogEntity entity, bool identity = false, bool returnId = false) 9 {10 this. identity = identity; 11 this. returnId = returnId; 12 return this. addObject (entity); 13}

 

1 /// <summary> 2 // Add logon logs multi-database support 3 /// </summary> 4 /// <param name = "entity"> logon log entity </param> 5 public string AddObject (BaseLoginLogEntity entity) 6 {7 string key = string. empty; 8 if (! String. isNullOrWhiteSpace (entity. id) 9 {10 key = entity. id. toString (); 11} 12 SQLBuilder sqlBuilder = new SQLBuilder (DbHelper, this. identity, this. returnId); 13 sqlBuilder. beginInsert (this. currentTableName, this. primaryKey); 14 if (! This. identity) 15 {16 // The primary key is already specified here, so you do not need to return the primary key 17 sqlBuilder. returnId = false; 18 sqlBuilder. setValue (this. primaryKey, entity. id); 19} 20 else21 {22 if (! This. returnId & (DbHelper. currentDbType = CurrentDbType. oracle | DbHelper. currentDbType = CurrentDbType. DB2) 23 {24 if (DbHelper. currentDbType = CurrentDbType. oracle) 25 {26 sqlBuilder. setFormula (this. primaryKey, "SEQ _" + this. currentTableName. toUpper () + ". NEXTVAL "); 27} 28 if (DbHelper. currentDbType = CurrentDbType. DB2) 29 {30 sqlBuilder. setFormula (this. primaryKey, "next value for seq _" + this. currentTableName. toUpper (); 31} 32} 33 else34 {35 if (this. identity & (DbHelper. currentDbType = CurrentDbType. oracle | DbHelper. currentDbType = CurrentDbType. DB2) 36 {37 BaseSequenceManager sequenceManager = new BaseSequenceManager (DbHelper); 38 entity. id = sequenceManager. increment (this. currentTableName); 39 sqlBuilder. setValue (this. primaryKey, entity. id); 40} 41} 42} 43 this. setObject (sqlBuilder, entity); 44 sqlBuilder. setDBNow (BaseLoginLogEntity. fieldCreateOn); 45 if (this. identity & (DbHelper. currentDbType = CurrentDbType. sqlServer | DbHelper. currentDbType = CurrentDbType. access) 46 {47 key = sqlBuilder. endInsert (). toString (); 48} 49 else50 {51 sqlBuilder. endInsert (); 52} 53 if (this. identity & (DbHelper. currentDbType = CurrentDbType. oracle | DbHelper. currentDbType = CurrentDbType. DB2) 54 {55 return entity. id. toString (); 56} 57 return key; 58}

It can be seen from the code that no value is assigned to the ID. I wanted to change the underlying code and add a GUID to it as the ID value, later, considering that this was not a good practice,

Considering that you can directly change the field type in the database, change the original nvarchar (50) type to the uniqueidentifier type, and set the default value (newid ()).

For example:

Run the project again. The error does not appear.

If you encounter some problems in the general permission management system development project, you can join the "general permission management system" QQ chat group: 371168832 to communicate and improve together.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.