0

我採取鬆散地基於對這篇文章的通知系統:ASP.net modalpopup

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

其中一個變化,我需要做的是展現出modalpopup(使用用戶登錄後如果用戶發佈了要閱讀的通知,則使用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 

回答

1

我假設您使用的是標準登錄控件?如果您想要更多地控制重定向行爲,您可以編寫自己的登錄控件並插入自己的重定向邏輯。

編寫自己的登錄控件非常簡單,因爲您可以很輕鬆地使用.NET授權方法。在捕獲用戶的用戶名/密碼後,您可以使用以下幾行驗證並設置用戶的cookie:

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

是的我正在使用「標準登錄控制」,更新了問題。 – DavRob60 2010-06-08 14:52:33