資源簡介
說明:
用C#語言實現的ASP.NET在線投票系統的簡單例子,可以顯示投票人數,投票百分比例對比等,使用Cookie技術實現 ^_^

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Web;
using?System.Web.UI;
using?System.Web.UI.WebControls;
public?partial?class?_Default?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????}
????protected?void?ImageButton1_Click(object?sender?ImageClickEventArgs?e)
????{
????????string?userIP?=?Request.UserHostAddress.ToString();
????????HttpCookie?oldCookie?=?Request.Cookies[“userIP“];
????????if?(oldCookie?==?null)
????????{
????????????int?flag?=?RadioButtonList1.SelectedIndex;
????????????switch?(flag)
????????????{
????????????????case?0:
????????????????????Component.WriteCount(Server.MapPath(“Result1.txt“));
????????????????????break;
????????????????case?1:
????????????????????Component.WriteCount(Server.MapPath(“result2.txt“));
????????????????????break;
????????????????case?2:
????????????????????Component.WriteCount(Server.MapPath(“Result3.txt“));
????????????????????break;
????????????}
????????????Clientscript.RegisterStartupscript(this.GetType()?““?“alert(‘投票成功!‘)“?true);
????????????HttpCookie?newCookie?=?new?HttpCookie(“userIP“);
????????????newCookie.Expires?=?DateTime.MaxValue;
????????????newCookie.Values.Add(“IPAddress“?userIP);
????????????Response.AppendCookie(newCookie);
????????}
????????else
????????{
????????????string?userOldIP?=?oldCookie.Values[“IPAddress“];
????????????if?(userIP.Trim()?==?userOldIP.Trim())
????????????{
????????????????Clientscript.RegisterStartupscript(this.GetType()?““?“alert(‘一個IP地址只能投一次票,謝謝您的參與!‘)“?true);
????????????}
????????????else
????????????{
????????????????HttpCookie?newCookie?=?new?HttpCookie(“userIP“);
????????????????newCookie.Values.Add(“IPAddress“?userIP);
????????????????newCookie.Expires?=?DateTime.MaxValue;
????????????????Response.AppendCookie(newCookie);
????????????????int?flag?=?RadioButtonList1.SelectedIndex;
????????????????switch?(flag)
????????????????{
????????????????????case?0:
????????????????????????Component.WriteCount(Server.MapPath(“Result1.txt“));
????????????????????????break;
????????????????????case?1:
????????????????????????Component.WriteCount(Server.MapPath(“result2.txt“));
????????????????????????break;
????????????????????case?2:
????????????????????????Component.WriteCount(Server.MapPath(“Result3.txt“));
????????????????????????break;
????????????????}
????????????????Clientscript.RegisterStartupscript(this.GetType()?““?“alert(‘投票成功!‘)“?true);
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-11-17?17:26??Vote\
?????目錄???????????0??2011-11-17?17:02??Vote\App_Code\
?????文件?????????700??2011-11-17?17:05??Vote\App_Code\Component.cs
?????文件????????1622??2011-11-17?17:27??Vote\Default.aspx
?????文件????????2622??2011-11-17?17:26??Vote\Default.aspx.cs
?????目錄???????????0??2011-11-17?16:56??Vote\Images\
?????文件??????100734??2010-03-25?15:34??Vote\Images\1.jpg
?????文件??????111734??2010-03-25?15:32??Vote\Images\2.jpg
?????文件????????1848??2010-03-25?15:37??Vote\Images\dc_03.gif
?????文件????????1790??2010-03-25?15:37??Vote\Images\dc_05.gif
?????文件????????1539??2010-03-25?15:35??Vote\Images\fh_03.gif
?????文件????????4230??2011-11-17?17:33??Vote\Result.aspx
?????文件????????1323??2011-11-17?17:39??Vote\Result.aspx.cs
?????文件???????????3??2011-11-17?17:26??Vote\Result1.txt
?????文件???????????4??2011-11-17?17:25??Vote\Result2.txt
?????文件???????????3??2011-11-17?17:39??Vote\Result3.txt
?????文件?????????761??2011-11-17?17:28??Vote\st
?????文件?????????292??2011-11-17?17:10??Vote\web.config
評論
共有 條評論