vb.net中按钮点击的唯一身份访问者的唯一号码?

时间:2011-03-21 07:36:18

标签: asp.net vb.net visual-studio-2008

如何生成唯一编号。 1,2,3等等....按下每个新用户的按钮..

下面提到的代码是vb.net中的readwrite编码...

但问题是它在按钮点击事件上为不同的用户生成相同的ID ...但我想要的是否。单击时间按钮将生成新的ID

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim FILE_NAME As String = Server.MapPath("counts.vbi")
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.Write(Literal1.Text)
            objWriter.Close()
        Else
        End If
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim FILE_NAME As String = Server.MapPath("counts.vbi")
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objStreamReader As New System.IO.StreamReader(FILE_NAME)
            Literal1.Text = objStreamReader.ReadToEnd
            Literal1.Text += 1
            objStreamReader.Close()
        End If
    End Sub

1 个答案:

答案 0 :(得分:0)

您可以像这样生成随机ID:

Guid.NewGuid().ToString("N")

希望这可以帮到你。

由于