知识大全 ASP.NET 3.5中的Login控件应用vb.net实现
Posted 知
篇首语:学向勤中得,萤窗万卷书。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 ASP.NET 3.5中的Login控件应用vb.net实现相关的知识,希望对你有一定的参考价值。
ASP.NET 3.5中的Login控件应用vb.net实现 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
The ASP NET login controls provide a robust login solution for ASP NET Web applications without requiring programming By default login controls integrate with ASP NET membership and forms authentication to help automate user authentication for a Web site It provides you with a ready to use user interface that queries the user name and password from the user and offers a Log In button for login It validate user credentials against the membership API and encapsulating the basic froms authentication functionality like redirecting back to the original requested page in a restricted area of you application after the successful login
The Login control displays a user interface for user authentication The Login control contains text boxes for the user name and password and a check box that allows users to indicate whether they want the server to store their identity using ASP NET membership and automatically be authenticated the next time they visit the site
The Login control has properties for customized display for customized messages and for links to other pages where users can change their password or recover a fotten password The Login control can be used as a standalone control on a main or home page or you can use it on a dedicated login page If you use the Login control with ASP NET membership you do not need to write code to perform authentication However if you want to create your own authentication logic you can handle the Login control s Authenticate event and add custom authentication code
Note Login controls might not function correctly if the Method of the ASP NET Web page is changed from POST (the default) to GET
Start Microsoft Visual Studio
Create a new ASP NET WebSite using Visual Basic Like this:
Drag and drop Login control on page from ToolBox Figure Whenever user hits the Log In button the control automatically validates the user name and password using the membership API function Membership ValidateUse() and then calls FormAuthentication redirectFromLoginPage() if the validation was successful All options on the UI of the LoginControl affect the input delivered by the control to these methods For Example if you click the Remember me next time check box it passes the value true to the createPresistentCookie parameter of the RedirectFromLoginPage() method Therefore the FormAuthenticateModule creates a persistent cookie There are three Login Tasks by default Auto Format you can select default schemes Convert To Template You can edit content of Login Control Administer Website You can configure Web Site Administration Tools Like Security Application Provider
Figure
<form id= form runat= server >
<div>
<asp:Login ID= Login runat= server BackColor= #F F DE BorderColor= #CCCC BorderStyle= Solid BorderWidth= px Font Names= Verdana Font Size= pt >
<TitleTextStyle BackColor= # B B Font Bold= True ForeColor= #FFFFFF />
</asp:Login>
</div>
</form>
You can change styles of LoginControl using css too Like this:
LoginControl
background color:#F F DE;
border color:#CCCC ;
border style:solid;
border width: px;
font family:Verdana;
font size: px;
And now apply css to control:
< xmlns= >
<head runat= server >
<title>Login Control</title>
<link type= text/css rel= Stylesheet />
</head>
<body>
<form id= form runat= server >
<div>
<asp:Login ID= Login runat= server CssClass= LoginControl >
<TitleTextStyle BackColor= # B B Font Bold= True ForeColor= #FFFFFF />
</asp:Login>
</div>
</form>
</body>
</>
If you running the page and if the CSS file is placed in a directory where anonymous access is denied the add the following configuration for the CSS file to you nfig file
<location path= StyleSheet css >
<system web>
<authorization>
<allow users= * />
</authorization>
</system web>
</location>
You can add several hyperlinks to your Login control such as hyperlink to a help text page or a hyperlink to to a registration page
<asp:Login ID= Login runat= server CssClass= LoginControl
CreateUserText= Register
CreateUserUrl= ~/Register aspx
HelpPageText= Additional Help HelpPageUrl= ~/Help aspx
InstructionText= Please enter your user name and password for login >
<TitleTextStyle BackColor= # B B Font Bold= True ForeColor= #FFFFFF />
</asp:Login>
Looks like this :
Here is VB Code:
Imports System
Imports System Collections Generic
Imports System Linq
Imports System Web
Imports System Web UI
Imports System Web UI WebControls
Imports System Data SqlClient
Partial Class _Default
Inherits System Web UI Page
Protected Sub Page_Load(ByVal sender As Object ByVal e As System EventArgs) Handles Me Load
If Not Me IsPostBack Then
ViewState( LoginErrors ) =
End If
End Sub
Protected Sub Login _Authenticate(ByVal sender As Object ByVal e As AuthenticateEventArgs)
If YourValidationFunction(Login UserName Login Password) Then
e Authenticated = true;
Login Visible = False
MessageLabel Text = Successfully Logged In
Else
e Authenticated = False
End If
End Sub
Protected Sub Login _LoginError(ByVal sender As Object ByVal e As EventArgs)
If ViewState( LoginErrors ) Is Nothing Then
ViewState( LoginErrors ) =
End If
Dim ErrorCount As Integer = CInt(ViewState( LoginErrors )) +
ViewState( LoginErrors ) = ErrorCount
If (ErrorCount > ) AndAlso (Login PasswordRecoveryUrl <> String Empty) Then
Response Redirect(Login PasswordRecoveryUrl)
End If
End Sub
Private Function YourValidationFunction(ByVal UserName As String ByVal Password As String) As Boolean
Dim boolReturnValue As Boolean = False
Dim strConnection As String = server= ;database=Vendor;uid=sa;pwd=wintellect;
Dim sqlConnection As New SqlConnection(strConnection)
Dim SQLQuery As String = SELECT UserName Password FROM Login
Dim mand As New SqlCommand(SQLQuery sqlConnection)
Dim Dr As SqlDataReader
sqlConnection Open()
Dr = mand ExecuteReader()
While Dr Read()
If (UserName = Dr( UserName ) ToString()) And (Password = Dr( Password ) ToString()) Then
boolReturnValue = True
End If
Dr Close()
Return boolReturnValue
End While
Return boolReturnValue
End Function
End Class
If you insert wrong username and password then message will show like this:
If you insert correct usename password then redirect your page whereever you want
or you can show message in ErrorLabel like this:
I am attaching my database with application in App_Data folder if u want to use my database then attach my MDF file
Any question and queries ask me any time
cha138/Article/program/net/201311/13326相关参考
知识大全 ASP.NET入门教程 4.2.1 Login控件[4]
ASP.NET入门教程4.2.1Login控件[4] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
知识大全 ASP.NET入门教程 4.2.1 Login控件[2]
ASP.NET入门教程4.2.1Login控件[2] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
知识大全 ASP.NET入门教程 4.2.1 Login控件[1]
ASP.NET入门教程4.2.1Login控件[1] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
知识大全 ASP.NET 3.5中使用新的ListView控件
ASP.NET3.5中使用新的ListView控件 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
知识大全 在ASP.NET 3.5中使用新的ListView控件[1]
在ASP.NET3.5中使用新的ListView控件[1] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一
知识大全 在ASP.NET 3.5中使用新的ListView控件[3]
在ASP.NET3.5中使用新的ListView控件[3] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一
知识大全 在ASP.NET 3.5中使用新的ListView控件[2]
在ASP.NET3.5中使用新的ListView控件[2] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一
知识大全 在ASP.NET 3.5中使用新的ListView控件[4]
在ASP.NET3.5中使用新的ListView控件[4] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一
知识大全 在ASP.NET中用三个DropDownList控件应用
在ASP.NET中用三个DropDownList控件应用 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下
ASP.NET中的那些控件 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 这十几天来一直再看天轰