【问题标题】:Evaluating whether a page is the result of a referral from a particular page评估页面是否是来自特定页面的推荐结果
【发布时间】:2013-04-15 01:51:39
【问题描述】:

我有一个编辑个人资料页面,允许用户更改他们的信息 - 目前它只允许在“userprofiles”表中有记录的用户编辑他们的信息。我希望新注册的用户也能够编辑他们的个人资料。

此时,我正在使用 ASP.NET 会员系统和 Access 数据库中的适当 asp.net_ 表来存储用户凭据。 'userprofiles' 表是一个单独的表,其中包含更多个人信息。两个表之间没有链接

这是我的代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If IsCrossPagePostBack Then
        SeparateNewUserFunction()
        Return
    End If
    If Not IsPostBack Then
        DisplayData()
        SaveConfirmation.Visible = False
    End If
End Sub

如果有人对它的作用感兴趣,这是我的 DisplayData() 函数:

    Protected Sub DisplayData()
    Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
    Dim sql = "SELECT * FROM userprofiles WHERE TravellerName=@f1"
    Dim cmd = New OleDbCommand(sql, conn)
    cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
    conn.Open()
    Dim profileDr = cmd.ExecuteReader()
    profileDr.Read()
    Dim newEmailAddress = ""
    Dim newDescription = ""
    If Not IsDBNull(profileDr("EmailAddress")) Then newEmailAddress = profileDr.Item("EmailAddress")
    If Not IsDBNull(profileDr("Description")) Then newDescription = profileDr.Item("Description")
    If Not IsDBNull(profileDr("AvatarURL")) Then ProfilePic.ImageUrl = profileDr.Item("AvatarURL")
    description.Text = newDescription
    email.Text = newEmailAddress
    conn.Close()

End Sub

与其检查“userprofiles”表中是否存在与当前用户的 User.Identity.Name 匹配的记录,我认为只评估用户是否刚刚从注册表重定向会更容易.aspx 页面。 (如果这个评估是真的,那么正如你在上面看到的,一个单独的“新用户”函数将被调用)。

这是我的逻辑,但我不知道 VB.NET 是否有“referrer”或“isReferred”表达式? (正如你所见,我认为 isCrossPagePostback 可能是正确的,但没有运气!)

有什么想法吗?

【问题讨论】:

  • 我还强烈建议您同时学习 ASP.NET MVC,或者在您熟悉 Web 表单之后不久。
  • 好的,谢谢。我会调查的!

标签: asp.net vb.net ms-access postback


【解决方案1】:

您需要检查记录是否存在并以此为基础。这是唯一正确的方法。如:

  1. 如果您引入一个新页面来处理注册怎么办?这个逻辑不成立。
  2. 如果有一天你退休了,而下一个人决定重命名 Register.aspx 页面怎么办?这个逻辑不成立。
  3. 如果用户点击返回按钮并再次单击注册按钮怎么办?这种逻辑可能会被打破。

您还应该考虑该表的外键和唯一约束,以及使用 UserId 而不是 TravellerName。 TravellerName 可以更改,UserId 不会。

...是的,您可以使用HttpRequest.ServerVariables 来引用页面,这将为您提供IIS Server Variables 的列表。

【讨论】:

    猜你喜欢
    • 2016-12-10
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2021-05-17
    相关资源
    最近更新 更多