LoggedIn 事件中的 ASP.net modalpopup

发布于 2024-09-04 17:47:17 字数 1644 浏览 4 评论 0原文

我正在实现一个大致基于本文的公告系统:

https://web.archive.org/web/20211020111733/https://www.4guysfromrolla.com/articles/110409-1.aspx

i 的更改之一需要做的是,如果用户收到要阅读的通知,则在用户登录后显示模式弹出窗口(使用 ModalPopupExtender)。

弹出窗口不会显示,因为用户在标准登录控件的 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

I'm implementing a Announcement system that is loosely based on this article:

https://web.archive.org/web/20211020111733/https://www.4guysfromrolla.com/articles/110409-1.aspx

One of the changes the i need to do is to show a modalpopup (using the ModalPopupExtender) after the user login if the user got announcement to read.

The pop-up does not show because the user get redirected after the LoggedIn event of the standard login control.
How could I avoid that?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此生挚爱伱 2024-09-11 17:47:17

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

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

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

I assume you're using the standard login control? If you want a little more control over the redirect behavior you can write your own login control and insert your own redirect logic.

Writing your own login control is fortunately very simple as you can tap into the .NET authorization methods pretty easily. After you capture the user's username/password you can verify and set the user's cookie using the lines below:

If Membership.ValidateUser(username, password) Then
    ' add your redirect logic here
    FormsAuthentication.SetAuthCookie(username, rememberMe)
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文