• Increase font size
  • Default font size
  • Decrease font size
Home Development jQuery Error in ASP.NET website

jQuery Error in ASP.NET website

E-mail Print PDF

I felt it necessary to share this information in hopes it saves someone else time and hassle.  I was recently working on an ASP.NET website for a client that made use of jQuery and jQueryUI.  The site worked fine when I referenced the jQuery files on the CDN (see Snippet 1 below).

Code Snippet 1.

javascript cdn reference

There were concerns about the website linking to externally hosted scripts, so I needed to download and reference the jQuery files (jquery-1.4.4.min.js, jquery-ui-1.8.7.custom.min.js) locally.  When I would reference the jQuery files locally (see Snippet 2),

Code Snippet 2.

javascript local reference

The site would break and produce the following error:

Microsoft JScript runtime error: object expected

I found many references to this error when searching the net, but they all referenced the PATH of the jQuery files and making sure it was correct.  I saw many solutions to map the PATH at run time, but no matter what the error persisted. From all the forum posts I read, it seems like many others could not resolve their issue unless they reference the files on CDN (Snippet 1 above).

After I realized the issue I had, it was obvious, but it took my some time to come to this conclusion.  I was restricting site access to unauthenticated users and redirecting to a login page (the login page was using jQuery functionality).  Using the ASP.NET Configuration tool, I blocked access to all site files except the login page (web config entry below).

This in effect was restricting access to the local jQuery files when an unauthenticated user visited the login page, causing the "object expected" error.   The solution to this is granting access to the directory holding the scripts.  I accomplished this by creating a new web.config file with the text below and placing it in the scripts directory.   

It is also noteworthy to mention the same condition can apply if you are using master pages and external CSS files.  If your login page references these items, anonymous users must have access to them.  I hope I am able to help someone out by posting this article.  If you have any questions, feel free to post them in the comments below or in the forum.  Good Luck!

Recommended Web Hosting

Free Stuff!

Featured FREE Resource:

Featured FREE Resource: