Web. config
<Configuration>
......
<System. Web>
<Database>
<Add key = "strconn" value = "Server = 107.120.65.99; database = dB; uid = dB; Pwd = DB"/>
</Database>
</System. Web>
......
</Configuration>
Global. asax. CS
Protected void session_end (Object sender, eventargs E)
{
Application. Lock ();
Application. Remove (session. sessionid. tostring ());
Application ["ol_usercount"] = (INT) application ["ol_usercount"]-1;
Application. Unlock ();
}
Login. aspx
<Table class = "logintable">
<Tr> <TD colspan = "2" class = "tdcaption"> <font class = "fcaption"> zookeeper without authorization </font> </TD> </tr>
<Tr> <TD> <font class = "font100"> zookeeper upload ID: </font> </TD> </tr>
<TD> <asp: textbox cssclass = "itxt" id = "txtname" runat = "server"> </ASP: textbox> </TD> </tr>
<Tr> <TD> <font class = "font100"> zookeeper without authorization: </font> </TD>
<TD> <asp: textbox cssclass = "itxt" id = "txtpwd" textmode = "password" runat = "server"> </ASP: textbox> </TD> </tr>
<Tr> <TD> <asp: button cssclass = "iButton" id = "btnsubmit" text = "login" runat = "server"> </ASP: button> </TD>
<TD> <input type = "reset" class = "iButton" name = "btnreset" value = "reset"> </TD> </tr>
</Table>
Login. aspx. CS
Using system. Collections. Specialized;
Using system. Data. sqlclient;
Public void loginbysql ()
{
String strconn = (string) (namevaluecollection) Context. getconfig ("system. Web/Database") ["strconn"];
Using (sqlconnection conn = new sqlconnection (strconn ))
{
Sqlcommand cmd = new sqlcommand ("sp_idpwd", Conn );
Cmd. commandtype = commandtype. storedprocedure; // The stored procedure is used here.
Cmd. Parameters. Add ("@ ID", sqldbtype. varchar, 20 );
Cmd. Parameters. Add ("@ PWD", sqldbtype. varchar, 20 );
Cmd. Parameters ["@ ID"]. value = txtname. text;
Cmd. Parameters ["@ PWD"]. value = txtpwd. text;
Conn. open ();
Using (sqldatareader DR = cmd. executereader ())
{
If (dr. Read ())
{
Bool notol = true;
For (INT I = 0; I <application. Count; I ++)
{
If (application [application. getkey (I). tostring ()]. tostring () = Dr ["userid"]. tostring ())
Notol = false;
}
If (notol)
{
Application [session. sessionid. tostring ()] = Dr ["userid"]. tostring ();
Application ["ol_usercount"] = (INT) application ["ol_usercount"] + 1;
Session ["username"] = Dr ["username"]. tostring (); // sessions
Response. Redirect ("./main/Main. aspx ");
}
Else
Message. Text = "logged in ";
}
Else
{
Message. Text = "Incorrect password ";
}
}
}
}
Stored Procedure
Alter procedure DBO. sp_idpwd
(
@ ID varchar (20 ),
@ PWD varchar (20)
/* @ PWD datatype output */
)
As
Set nocount on
Select * from [dB]. [dB]. [admin] Where (Userid = @ ID) And ([Password] = @ PWD)
Return