我正在尝试使用以下内容检测iphone / ipad等:
Dim iphone As Boolean = False
Dim userAgent = HttpContext.Current.Request.UserAgent.ToLower()
' iPhone is there
If userAgent.Contains("iphone") Then
iphone = True
ElseIf userAgent.Contains("ipad") Then
iphone = True
ElseIf userAgent.Contains("itouch") Then
iphone = True
End If
但是,我注意到很多失败/例外:
Dim userAgent = HttpContext.Current.Request.UserAgent.ToLower()
任何人都可以告诉我可能导致异常的原因(详情如下)?
谢谢,Mark
System.NullReferenceException
Object reference not set to an instance of an object.
[System.NullReferenceException]
Inner Exception
Exception Message: Object reference not set to an instance of an object.
at book.Page_Load(Object sender, EventArgs e) in xxxxxxxxx\xxxx.aspx.vb:line 110
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[System.Web.HttpUnhandledException]
Exception Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.book_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)