Solved

Error while checking browser compatibility

Posted on 2013-06-27
2
368 Views
Last Modified: 2013-06-30
Hello Experts,

Below is the code,


'''''chrome compatibility
    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If (Request.ServerVariables("http_user_agent").IndexOf("Chrome", StringComparison.CurrentCultureIgnoreCase) <> -1) Then
            Page.ClientTarget = "uplevel"
        End If
        If (Request.ServerVariables("http_user_agent").IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) <> -1) Then
            Page.ClientTarget = "uplevel"
        End If
    End Sub

Open in new window


Sometimes we are getting below error,

Object reference not set to an instance of an object.

at line,

 If (Request.ServerVariables("http_user_agent").IndexOf("Chrome", StringComparison.CurrentCultureIgnoreCase) <> -1) Then

Open in new window


Can anyone help with this?

Thanks.
0
Comment
Question by:dotsandcoms
2 Comments
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 250 total points
ID: 39283610
This may be an answer to your problem, it is also chrome related as is yours:
http://forums.asp.net/t/1551330.aspx/1
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 39284104
You can add a check to ensure that string is not null.

Change this

 If (Request.ServerVariables("http_user_agent").IndexOf("Chrome", StringComparison.CurrentCultureIgnoreCase) <> -1) Then

to

If Not String.IsNullOrEmpty(Request.ServerVariables("http_user_agent")) Then
 If (Request.ServerVariables("http_user_agent").IndexOf("Chrome", StringComparison.CurrentCultureIgnoreCase) <> -1) Then
End If
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now