導航:首頁 > 萬維百科 > asp網頁設計用戶注冊

asp網頁設計用戶注冊

發布時間:2020-10-30 21:35:43

1、asp 設計網站的登錄系統

1,先建立一個資料庫UserTest。
2,在裡面建立一個表叫UsersTable,設計表,建立三個列:u_id, u_name, u_pwd。
3,u_id是int數據類型,自增1;u_name是nvarchar類型,長度12;u_pwd是varchar類型,長度12,然後保存該表。
4,打開表,在第一行u_name輸入「abc」,u_pwd輸入「abc」。關閉表。
5,打開VS,新建一個Web項目。雙擊默認的default.aspx頁面,然後將 <body>... </body>替換成下面的代碼:

HTML code
<!-- 替換-->
<body style="margin: 0px">
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 50px">
<tr>
<td style="vertical-align: middle; width: 50%; text-align: center; font-weight: bold; font-size: 25px; color: #003366; font-family: Arial;">yunleilian 的登錄示範</td>
<td style="vertical-align: middle; text-align: left">
<asp:Panel ID="pnlLogin" runat="server" Height="30px" Width="100%">
用戶名:<asp:TextBox ID="txbUserName" runat="server"></asp:TextBox>密碼:
<!-- 對於密碼TextBox,應把TextMode屬性設置為Password,這樣輸入的值會以****形式出現,保護密碼在輸入時不被別人看到 -->
<asp:TextBox ID="txbUserPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="btnLogin" runat="server" Text="登錄" OnClick="btnLogin_Click" /></asp:Panel>
<asp:Panel ID="pnlWelcome" runat="server" Height="30px" Width="100%">
<asp:Label ID="lblWelcome" runat="server"></asp:Label>
<asp:Button ID="btnQuit" runat="server" CausesValidation="False" Text="退出" Width="146px" OnClick="btnQuit_Click" /></asp:Panel>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100px">
<tr>
<td style="vertical-align: middle; text-align: center">
<!-- 這個用來顯示登錄是否成功的信息 -->
<asp:Label ID="lblMessage" runat="server" ForeColor="#C00000"></asp:Label></td>
</tr>
</table>
</form>
</body>
<!-- 替換結束 -->

6,按F7,進入代碼視圖,在Page_Load()里寫下面的代碼:

C# code
protected void Page_Load(object sender, EventArgs e)
{
//確保頁面是第一次被訪問
if (!Page.IsPostBack)
{
CheckPageStatus();
}
}

//通過判斷Session["UserName"]是否為空檢查頁面是否已登錄(登錄成功時會為Session["UserName"]注入值,就不空了。。否則就認為沒有登錄)。
private void CheckPageStatus()
{
if (Session["UserName"] != null)
{
pnlLogin.Visible = false;
pnlWelcome.Visible = true;
lblWelcome.Text = "歡迎登錄," + Session["UserName"].ToString() + " 同志";
}
else
{
pnlWelcome.Visible = false;
pnlLogin.Visible = true;
}

//這個用來接收登錄或退出後的信息。個人習慣,你也可以不這么做。
if (Session["Message"] != null)
{
lblMessage.Text = Session["Message"].ToString();
Session.Remove("Message");
}
else
lblMessage.Text = "";
}

7,先告一段落,按F5運行下,看看效果,你會發現當沒有登錄時,「退出」那部分沒有顯示。真神奇啊。
8,然後關閉這個IE頁面,按VS左下角的「設計」,切換到設計視圖。
9,雙擊設計視圖的「登錄」按鈕,為它編寫登錄代碼如下:

C# code
protected void btnLogin_Click(object sender, EventArgs e)
{
//下面的登錄方法只是我的習慣而已,我常用DataTable做所有的事情。建議你不要依賴它……否則會被人笑話的……登錄的好方法有很多,參考下就好了。
string strConnection = "SERVER=(local);DATABASE=UserTest;UID=sa;PWD=";//PWD=後面寫上你的SQL SERVER 的 sa密碼。
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(strConnection);
//SQL 語句會吧?不會沒辦法,照抄吧。
string strSql = "SELECT * FROM UsersTable WHERE u_name='" + txbUserName.Text + "' AND u_pwd='" + txbUserPassword.Text + "'";
//SqlDataAdapter這東西有什麼用,建議你去查MSDN。
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(strSql, cn);
System.Data.DataTable dt = new DataTable();
da.Fill(dt);

if (dt.Rows.Count > 0)
{
Session["UserName"] = dt.Rows[0]["u_name"].ToString();
Session["Message"] = "登錄成功!";
Response.Redirect("default.aspx");
}
else
{
Session["Message"] = "登錄失敗。請重新登錄。";
Response.Redirect("default.aspx");
}
}

10,再按F5測試下,在用戶名和密碼內輸入123,按下「登錄」按鈕,會提示登錄失敗。如果都輸入abc,就會提示登錄成功。因為資料庫內只有abc這個用戶。
11,關閉IE頁面,最後我們做退出。
12,回到設計視圖,雙擊「退出」按鈕,為它編寫下面的代碼:

C# code
protected void btnQuit_Click(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
Session.Remove("UserName");
Session["Message"] = "退出成功,歡迎您再來啊";
Response.Redirect("default.aspx");
}
}

13,按F5運行,登錄成功後,按「退出」按鈕,系統會提示已經退出。
14,為了驗證用戶是否已登錄,你需要在所有需要登錄的頁面的Page_Load()內添加:

C# code

if(Session["UserName"]!=null)
//用戶可以訪問。
else
//用戶不能訪問,扔回到登錄頁面:Response.Redirect("login.aspx");

15,基本如此,搞定。

2、asp網頁設計中,怎麼實現用戶登錄,並且登陸狀態保持在當前頁面,類似於這種

html5以前是不可能實現,html頁面之間的參數傳遞,但是現在可用localStorage或者sessionStorage來實現,百度下就有了。

3、jsp/asp實現用戶登錄界面,網頁加密(不用資料庫)-網頁設計

不建議用js,很容易就查到用戶名和密碼
asp簡單認證

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
if request.Form("username")="用戶名" then
if request.Form("password")="密碼(密碼不能用中文)" then
response.Redirect("加密網頁網址")
end if
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>用戶名:<input type="text" name="username" id="username" /></p>
<p>密 碼:<input type="password" name="password" id="password" /></p>
<p><input type="submit" name="button" id="button" value="登錄" /></p>
</form>
</body>
</html>

4、ASP動態網頁製作,製作一個聊天室,包括1用戶登錄界面:新用戶進行注冊,老用戶直接登錄進入。

建議你去圖書館借一本ASP的書籍,很多這方面的詳細解答,我一般是用DREAMWEAVER做,不用一個一個代碼去編

5、如果要設計網站的注冊頁面,將用戶注冊的信息保存到資料庫中,使用ASP.NET如何設計和實現?

樓上說的都對!!!整個操作就兩部分,建立相應的資料庫和前後台的編寫內
通常來說:容用戶注冊無非就是一個ID,用戶名,密碼,備注或者加些什麼用戶類型啥的,這樣你的數據表結構就可以有這么幾個列:id,用戶名,密碼,備注 基本都是字元串型就可以了,長度自己決定。
至於頁面前台的,就是拖幾個label控制項,幾個textbox控制項,幾個按鈕就行了
用戶名: textbox1
密碼: textbox2 不過密碼框一般都是設置成*顯示,textmode=password
重復密碼:textbox3
重置按鈕 注冊按鈕 退出按鈕

最簡單的注冊頁面都差不多這樣,至於後台編寫,無非就是一些SQL的寫入操作

6、在ASP動態網頁製作中,如何設置用戶注冊,登陸界面,具體過程是什麼?

如果用dreamweaver做的話,可以去百度里搜索「菜鳥也學DW做ASP」。
這個教程很不錯的,完全符合你的要求!

7、ASP網頁設計的問題。注冊頁面做好了,登陸頁面怎麼做呢,要求帶驗證碼的,求好心人幫忙

既然注冊都成功了,那登錄也差不多的,無非就是輸入用戶名和密碼以及驗證碼後,先判斷輸入的驗證碼的值與網站隨機產生的SESSION或COOKIES是否相符,如果相符了,再把用戶名和密碼去查找資料庫之中對應的用戶名和密碼,如果找到記錄了,就登錄成功了,反之則登錄失敗!

8、asp網頁設計中用戶登錄

<script language=javascript>
<!--
//驗證輸入
function CheckForm()
{
if(document.Login.uid.value=="")
{
alert("請輸入用戶名!");
document.Login.uid.focus();
return false;
}
if(document.Login.pwd.value == "")
{
alert("請輸入密碼!");
document.Login.pwd.focus();
return false;
}
if (document.Login.verifycode.value==""){
alert ("請輸入您的驗證碼!");
document.Login.verifycode.focus();
return(false);
}
}
-->
</script>
//表單
FORM name="Login" action="admin_check.asp" method="post" onSubmit="return CheckForm();">
<table width="682" height="170" border="0" align="center" cellpadding="0" cellspacing="0" background="images/backlogin.jpg"class="t_table">
<tr>
<th width="134" height="100" scope="col"> </th>
<th width="53" scope="col"> </th>
<th width="84" scope="col"> </th>
<th width="100" scope="col"> </th>
<th width="111" scope="col"> </th>
<th width="44" scope="col"> </th>
</tr>
<tr>
<td height="35"> </td>
<td><span class="STYLE3">管理員:</span></td>
<td colspan="2"><input name="uid" class="inputname" type="text" id="uid" style="border: 1px solid #999999;FONT-SIZE: 9pt; height:21;width:165" size="16"></td>
<td rowspan="3"> </td>
<td> </td>
</tr>
<tr>
<td height="35"> </td>
<td><span class="STYLE3">密  碼:</span></td>
<td colspan="2"><input name="pwd" class="inputpassword" type="password" id="pwd" style="border: 1px solid #999999;FONT-SIZE: 9pt; height:21;width:165" size="16"></td>
<td> </td>
</tr>
<tr>
<td height="35"> </td>
<td>驗證碼:</td>
<td><input name=verifycode type=text value="<%If GetCode=9999 Then Response.Write "9999"%>" maxlength=4 size=10 style="border: 1px solid #999999; FONT-SIZE: 9pt;"></td>
<td><img src=GetCode.asp></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="4" valign="middle">   
<input name="button" type="image" src="images/login.gif" width="74" height="39" border="0">       <a href="../index.asp"><img src="images/quxiao.gif" width="75" height="39" border="0"></a></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="4"> </td>
<td> </td>
</tr>
</table>
</FORM>
以上的放在同一個asp文件中
//admin_check.asp
<%response.Expires = 0%>
<!--#include file="conn.asp"-->
<!--#include file="md5.asp"-->
<%
'防SQL注入
function errsql(strget)
strcheck=strget
dim nothis(16)
nothis(0) = "net user"
nothis(1) = "xp_cmdshell"
nothis(2) = "/add"
nothis(3) = "exec%20master.dbo.xp_cmdshell"
nothis(4) = "net localgroup administrators"
nothis(5) = "select"
nothis(6) = "count"
nothis(7) = "asc"
nothis(8) = "char"
nothis(9) = "mid"
nothis(10) = "'"
nothis(11) = """"
nothis(12) = "insert"
nothis(13) = "delete"
nothis(14) = "drop"
nothis(15) = "truncate"
nothis(16) = "from"
for i=1 to ubound(nothis)
if instr(strget,nothis(i)) then
response.write "<script language=javascript>alert('輸入信息含有非法字元,請重新輸入!');history.go(-1);</script>"
response.End
end if
next
errsql = strcheck
end function
%>
<%
dim admin,password,webpassword
admin=errsql(trim(request("uid")))
webpassword=errsql(trim(request("pwd")))
password=md5(webpassword)
if cstr(session("getcode"))<>cstr(trim(request("verifycode"))) then
response.Write "<script LANGUAGE='javascript'>alert('請輸入正確的驗證碼!');history.go(-1);</script>"
response.end
end if

set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from master where name='"&admin&"' and password='"&password&"' " ,conn,1,1
if not(rs.bof or rs.eof) then
if password=rs("password") then
session("admin")=trim(rs("name"))
session.Timeout=20
rs.Close
set rs=nothing
response.Redirect "index.asp"
else
response.write "<script LANGUAGE='javascript'>alert('對不起,登陸失敗!');history.go(-1);</script>"

end if
else
response.write "<script LANGUAGE='javascript'>alert('用戶名或密碼錯誤!');history.go(-1);</script>"

end if
%>
上面的conn.asp是連接Access資料庫的,資料庫和資料庫的表,自己建立沒問題吧

9、ASP做網頁後台,怎樣加入新用戶 並且設定用戶的許可權。

給你一點設計思路。

首先要有自己的資料庫,資料庫中用來儲存用戶的,賬號,密碼,訪問許可權,等等基本信息.

例如:設計資料庫欄位ID     賬號                工號        密碼              許可權            

                                     1   admin              00000      admin          1,1,1,1,1

                                     2 user                 00001        user               1,1,0,0,0

ID用來排序,賬號密碼用來登陸,許可權用來設定用戶訪問許可權,當然如果需要還可以增加用戶登陸的時間,IP等。

創建設計登陸頁面,通過賬號密碼登陸,當然也可以限制一下登陸可增加一個驗證碼。

設計網頁後台管理界面,傳統設計是,左右兩個窗體,左側為菜單活導航,右側窗體為內容(還可以更多組合)。

通過許可權可以設計左側導航欄的地址顯示或不顯示,右側工作窗體是否可以操作或顯示。

例如:admin 的許可權 1,1,1,1,1中,第一個1為可登陸許可權,第二個1為員工,第三個1為可以查看,第四個1可以修改,第五個1可以添加用戶(高級管理員)。(當然這些都是明文,如果安全需要可以做的更復雜一點。)通過不同許可權訪問不同頁面,或編輯不同內容。

當然最後要設計管理員的操作頁面,給用戶分配許可權,添加用戶頁面,修改密碼頁面等等。

總之,思路是這樣,一句兩句話也說不清楚,如果你有一些經驗,我說的你應該可以理解,如果,我說的你不能理解,最快的方法就是建議去百度一下網上的asp整站代碼看看別人的後天設計,適當的借鑒一下。

希望對你有用。

與asp網頁設計用戶注冊相關的知識