代码之家  ›  专栏  ›  技术社区  ›  DavRob60

日志中的ASP.NET ModalPopup事件

  •  0
  • DavRob60  · 技术社区  · 16 年前

    我正在实现一个基于本文的发布系统:

    http://www.4guysfromrolla.com/articles/110409-1.aspx

    我需要做的更改之一是在用户登录后显示ModalPopUp(使用ModalPopExtender)(如果用户要读取公告)。

    弹出窗口不显示,因为用户在发生标准登录控件的Loggedin事件后被重定向。 我怎么能避免呢?

    Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
            'See if this user has unread announcements
            Dim announcementAPI As AnnouncementBLL = New AnnouncementBLL
            Dim UnreadAnnouncementCount As Integer= announcementAPI.GetUnreadAnnouncementCount(Login1.UserName)
            If UnreadAnnouncementCount > 0 Then
                UnreadAnnouncementMessage.Text = String.Format("You have {0} Announcement that you did not read yet.", UnreadAnnouncementCount)
                'Show modal popup for announcement!
                UnreadAnnouncementModalPopup.Show()
    
                'add soothing so user don't get redirected.
    
            End If
    
        End Sub
     Protected Sub Read_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Read.Click
            Response.Redirect(String.Format("~/Announcements.aspx?RedirectUrl={1}", _
                                  Server.UrlEncode(FormsAuthentication.GetRedirectUrl(Login1.UserName, False))))
    
        End Sub
    
        Protected Sub Ignore_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Ignore.Click
            Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName, False))
        End Sub
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Chris Van Opstal    16 年前

    我假设您使用的是标准登录控件?如果您希望对重定向行为有更多的控制,您可以编写自己的登录控件并插入自己的重定向逻辑。

    幸运的是,编写自己的登录控件非常简单,因为您可以很容易地使用.NET授权方法。捕获用户的用户名/密码后,可以使用以下行验证和设置用户的cookie:

    If Membership.ValidateUser(username, password) Then
        ' add your redirect logic here
        FormsAuthentication.SetAuthCookie(username, rememberMe)
    End If
    
    推荐文章