| |

VerySource

 Forgot password?
 Register
Search
View: 928|Reply: 8

Everyone, help, how to vote once, you can't vote again, asp.net, graduate design comes, urgent !!

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 13:00:01
| Show all posts |Read mode
public class WebForm1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Butvote;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Butred;

private string voteID = "2";
        private void Page_Load (object sender, System.EventArgs e)
{
if (! this.IsPostBack)
{
// Create a connection
SqlConnection sqlcon = DB.care ();
sqlcon.Open ();
// Query poll title
SqlCommand cmd = new SqlCommand ("select voteTitle from voteMaster where voteID =" + this.voteID, sqlcon);
string title = Convert.ToString (cmd.ExecuteScalar ());
this.Label1.Text = title;
                // Query the content of the title
SqlCommand scd = new SqlCommand ("select voteDetailsID, voteItem from voteDetails where voteID =" + this.voteID, sqlcon);
SqlDataReader sdr = scd.ExecuteReader ();
this.RadioButtonList1.DataSource = sdr;
this.RadioButtonList1.DataTextField = "voteItem";
this.RadioButtonList1.DataValueField = "voteDetailsID";
Ranch
this.RadioButtonList1.DataBind ();
sdr.Close ();
sqlcon.Close ();

}
}

#region Web Form Designer Generated Code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}
Ranch
/// <summary>
/// Designer supports required methods-don't use code editor to modify
/// The contents of this method.
/// </ summary>
private void InitializeComponent ()
{
this.RadioButtonList1.SelectedIndexChanged + = new System.EventHandler (this.RadioButtonList1_SelectedIndexChanged);
this.Butvote.Click + = new System.EventHandler (this.Butvote_Click);
this.Butred.Click + = new System.EventHandler (this.Butred_Click);
this.Load + = new System.EventHandler (this.Page_Load);

}
#endregion

Ranch

private void Butvote_Click (object sender, System.EventArgs e)
{

SqlConnection sqlcon = DB.care ();
sqlcon.Open ();
SqlCommand com = new SqlCommand ();
com.Connection = sqlcon;
com.CommandText = "Update voteDetails set voteNum = voteNum + 1 where voteID =" + voteID + "and voteDetailsID =" + RadioButtonList1.SelectedValue.ToString ();
int vot = com.ExecuteNonQuery ();
Ranch
if (vot! = 0)
{
Response.Write ("<script language = 'javascript'> alert ('Vote successfully'); window.location.href = 'show.aspx? Voteid =" + this.voteID + "'; </ script>");
Ranch
}
else
{
Response.Write ("Vote failed");
}
sqlcon.Close ();
Ranch
}

private void RadioButtonList1_SelectedIndexChanged (object sender, System.EventArgs e)
{
Ranch
}

private void Butred_Click (object sender, System.EventArgs e)
{
Response.Redirect ("show.aspx? Voteid =" + this.voteID);
Ranch
}
}
}
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-2-10 20:30:01
| Show all posts
1.Set cookies and set a flag.
2. Save the peer IP to the database

The first method is slightly simpler.
Reply

Use magic Report

1

Threads

60

Posts

37.00

Credits

Newbie

Rank: 1

Credits
37.00

 China

Post time: 2020-2-10 23:30:01
| Show all posts
It is still more convenient to read cookies. If you have a special self-defined cookie, you can read it every time.
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-11 09:45:02
| Show all posts
It is better to save the IP to the database
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-11 14:15:01
| Show all posts
Can write the code, I don't know much about this!
Reply

Use magic Report

0

Threads

10

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-12 13:45:01
| Show all posts
Provide a method. Only registered users can vote. Then judge that the user has already voted when voting!
Reply

Use magic Report

0

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-13 19:45:01
| Show all posts
Read the IP, and determine whether the IP has been cast when voting.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-15 11:00:01
| Show all posts
Actually, it depends on the nature of this vote.
If it is only general and irrelevant voting, cookies are generally sufficient. The disadvantage is that you can vote after deleting cookies;
It is also possible to simply record the IP, and the disadvantage is equivalent to ignoring N users under the same IP (such as Internet cafes).
In the case of voting with rewards or contest-type voting, it is recommended to set up more responsible precautionary measures.
The method of registering users, then the management method depends on the user system. (If you cannot prevent multiple registrations, it is useless to judge the user)
I think it might be better to take a look.
After the vote, the cookie is recorded. Use js to determine whether to vote before the vote (saving server resources). If the cookie does not exist, judge by IP. If the IP is the same, judge the time difference between the two voting times. Do not look at your settings again.
----------------------
Maybe there is a better way. . . :)
Reply

Use magic Report

5

Threads

19

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-15 19:45:02
| Show all posts
shenmue024opinion, I agree
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list