2012-01-11 36 views
0

我已將雙因素身份驗證添加到我的移動ASP.Net Web App。當用戶成功輸入他們的用戶名和密碼時,通過電子郵件將密碼發送到他們存儲在數據庫中的電子郵件地址。我遇到的問題是,通知用戶他們沒有定義電子郵件,然後重新加載登錄頁面,但我的代碼沒有通知用戶,而只是重新加載Login.aspx頁面:向用戶顯示消息,然後放棄會話

Private Sub GeneratePin() 
    Dim r As New Random(System.DateTime.Now.Millisecond) 
    _Pin = CStr(r.Next(1000, 99999)) 
    _email = CIAppGlobals.CurrentUser.UsrContactEmail 

    With lblPin 
     .Text = "PIN has been emailed to the you please check your email now." 
    End With 

    If Not String.IsNullOrEmpty(_email) Then 
     Dim Message As String = " Your Mobile PIN number is " & _Pin & vbNewLine & "From IP Address: " & CIAppGlobals.AppSettings.ClientIP 

     Tools.SendEmail(CIAppGlobals.CurrentUser.UsrContactEmail, "Mobile App - Two Factor Authentication", Message) 

    Else 
     Dim sText As String = "Please contact the Administrator You do not have an email address defined within Application." 
     'DirectCast(HttpContext.Current.Handler, System.Web.UI.Page).ClientScript.RegisterStartupScript(Me.[GetType](), "test", "alert('" & sText & "')", True) 
     Response.Write("<script>alert('" & sText & "');</script>") 
     Thread.Sleep(5000) 

     'Session.Abandon() 
     'FormsAuthentication.SignOut() 

     Response.Redirect(ParentFolder & "/Login.aspx") 
    End If 

End Sub 

回答

2

您致電Response.Redirect()會導致您輸出的任何內容都不會顯示。你需要刪除它,然後輸出一個鏈接或一些JavaScript進入登錄頁面。

另外:您需要刪除對Thread.Sleep()的呼叫。這是造成不必要的延遲,並保持一個asp.net線程忙無所事事。這不是在做你認爲的......

+0

嗯,這是一個好主意,謝謝! – 2012-01-11 17:53:17