Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize login with three-tier architecture in the Internet

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

I would like to share with you how to log in in the three-tier architecture of the Internet. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!

Hierarchical thinking:

The three-tier development divides the whole business application into presentation layer, business logic layer, data access layer, database and so on, and clearly divides the client's presentation layer, business logic access, and data access and database access, which is conducive to the development, maintenance, deployment and expansion of the system.

In fact, to sum up, it is to achieve "high cohesion, low coupling". Using the idea of "divide and rule", the problem is divided into different solutions, which is easy to control, easy to extend, and easy to allocate resources.

Take logging in to demo as an example:

Factory + reflection + profile

Three-tier UML diagram:

Through the UML diagram, we can clearly see the dependencies between the layers.

NET design:

Each layer of code implementation:

UI layer

'--interface Imports Entity Imports BLL Public Class Login Private Sub Button1_Click (sender As Object, e As EventArgs) Handles Button1.Click Dim EntityUser As New Entity.EntityUser Dim BLLUser As New BLL.BLLUser EntityUser.User_ID = txtID.Text EntityUser.User_Key = txtKey.Text If BLLUser.GetBase (EntityUser) Then MsgBox ("login succeeded!") Else MsgBox ("login failed!") End If End Sub End Class

BLL layer

'--Dim DalF As New Factory, passing the interface type as a parameter when calling the factory Find the specific implementation object Imports Entity Imports [Interface] Imports FactoryClass Public Class BLLUser Public Function GetBase (ByVal EntityUser As Entity.EntityUser) As Boolean Dim DalF As New Factory Dim Entity_User As New Entity.EntityUser Entity_User.User_ID = EntityUser.User_ID Entity_User = DalF.Interface_User.GetBase (Entity_User) If Entity_User.User_ through the interface type in the factory Key = EntityUser.User_Key Then Return True Else Return False End If End Function End Class

Factory class

'- reflection + configuration file to achieve database access To change the database, just change the configuration file'--AppSetting reads the category string Imports [Interface] Imports System.Reflection Public Class Factory Private Shared ReadOnly AssemblyName As String = "DAL" Dim DataBase As String = System.Configuration.ConfigurationSettings.AppSettings ("sql") Function Interface_User () As [Interface]. InterfaceUser Dim ClassName As String = AssemblyName + "." + DataBase + "DALUser" Return CType (Assembly.Load (AssemblyName) .CreateInstance (ClassName)) [Interface] .InterfaceUser) End Function End Class

Interface interface layer

'--define the interface, inherit the DAL layer by reference, and implement the interface Imports Entity Public Interface InterfaceUser Function GetBase (Entity_User As Entity.EntityUser) As Entity.EntityUser End Interface

DAL layer

'- operate the database Imports Entity Imports [Interface] Imports System.Data.SqlClient Public Class DALUser: Implements [Interface]. InterfaceUser Dim ConnStr As String = System.Configuration.ConfigurationSettings.AppSettings ("ConnStr") Dim sqlconn As SqlConnection = New SqlConnection (ConnStr)'-connect to the receipt library Function GetBase (Entity_User As Entity.EntityUser) As Entity.EntityUser Implements [Interface]. InterfaceUser.GetBase Dim sqldata As String = "select * from User_Info where User_ ID=' "& Entity_User.User_ID &"'"- SQL statement Read all the information from User_Info Dim sqlcmd As New SqlCommand (sqldata, sqlconn)'- connect to the database, open the User_ Info table Dim sqlread As SqlDataReader'- SqlDataReader read the database, read only Try sqlconn.Open () sqlread = sqlcmd.ExecuteReader'--ExecuteReader method, query the database and get the results. ExecuteReader returns SqlDataReader sqlread.Read ()'--sqlcmd.ExecuteReader 's Read () reads the records in the table, and each call returns a result set of one row. Entity_User.User_ID = sqlread.Item ("User_ID") Entity_User.User_Key = sqlread.Item ("User_Key") Return Entity_User Catch ex As Exception Entity_User.User_Key = "" Return Entity_User End Try End Function End Class

Entity physical layer

Entity classes are responsible for the representation of entities and the transmission of data, and do not contain any logical content. Public Class EntityUser Private strUser_ID As String Private strUser_Key As String Public Property User_ID As String Get'- get value Return (strUser_ID)'- get User_ID property return strUser_ID End Get Set (value As String)'- set value StrUser_ID = value'- pass a value Put it in the value parameter End Set End Property Public Property User_Key As String Get Return (strUser_Key) End Get Set (value As String) strUser_Key = value End Set End Property End Class

Configuration file

The above is all the contents of the article "how to log in in the three-tier architecture of the Internet". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report