2012-01-11 65 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