开发者

ASP.net modalpopup in loggedIn event

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_Logged开发者_StackOverflow社区In(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 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜