1

I am trying to get the standard Visual Studio 2012 MVC4 Internet template and oAuth to work but it won't!

So here are the simple steps to recreate.

  1. Create new MVC4 Inernet Application
  2. In Package Manager console execute: update-package
  3. Un-comment OAuthWebSecurity.RegisterGoogleClient() in file AuthConfig.cs (I was under the impression that the Google oAuth does not need a key so un-commenting this line in the AuthConfig.cs file would enable it.)
  4. F5 to run app

at this point I see the following error:

Error when entering login page:

Unhandled exception at line 115, column 5 in http://localhost:63180/Scripts/jquery.unobtrusive-ajax.js

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'live'
  1. Click the login link on home page
  2. Click the Google Button

at this point I get this error:

ProtocolException was unhandled by user code
No OpenID endpoint found
ChiliYago
  • 11,341
  • 23
  • 79
  • 126

2 Answers2

4

The cause of the error and the solution

The cause is that jquery-unobtrusive-ajax.js who is in charge of supporting the unobtrusive ajax in ASP.NET MVC using jQuery live method. But this method was deprecated in jQuery 1.7 and has been removed in 1.9.

This method allowed an event associated with any DOM element present or future. The method to be used in place of live currently is the method on.

However the syntax is a bit different, since the method has more uses on jQuery.

$ ("form [data-ajax = true].") live ("submit", function (e) { ... }

modify the call to live with a call to on.

For on act like we happen to live on 3 parameters: The event (like live, will "submit") A selector (elements "children") is based selector which must always exist The handler function (like live).

In this case our line looks like:

$ ("body"). on ("submit", "form [data-ajax = true]", function (e) { ... }

I moved the selector to the second parameter of on and have made you a basic selector "body" (not the most optimal, but well I'm sure there always).

The idea is that the last function is associated with all current and future elements of type form [data-ajax = true] that are within the selector base (body).

For all other calls to live (there are 3 more) make the same substitution that we be as follows:

$ ("body"). on ("click", "form [data-ajax = true]: submit", function (e) { ... }
$ ("body"). on ("click", "a [data-ajax = true]", function (e) { ... }
$ ("body"). on ("click", "form [data-ajax = true] input [type = image]", function (e) { ... }

And ready! With this we have recovered ajax functionality MVC unobtrusive and your application should work properly again!

translated from: http://geeks.ms/blogs/etomas/archive/2013/01/18/jquery-1-9-y-el-unobtrusive-ajax-de-asp-net-mvc.aspx

da7rutrak
  • 548
  • 3
  • 13
s_h
  • 1,476
  • 2
  • 27
  • 61
2

The unobtrusive library in NuGet has not been updated and does not work with jQuery 1.9.

See Unobtrusive Ajax stopped working after update jQuery to 1.9.0

Community
  • 1
  • 1
Jasen
  • 14,030
  • 3
  • 51
  • 68
  • This fixes the live error but now the No Endpoint Found error when attempting oauth with google still remains. Should it be gone as well with this fix? – ChiliYago Feb 08 '13 at 16:21
  • Following your steps I can't reproduce the problem. How did you fix the jQuery problem? I manually replaced live with on. Try a new project without updating the packages and see if the Google login works. – Jasen Feb 08 '13 at 18:57
  • Are you behind a firewall? http://stackoverflow.com/questions/5788236/no-openid-endpoint-found – Jasen Feb 08 '13 at 19:23
  • Yes I found creating a new solution without updating anything seems to work. I'm Looking for a graceful solution that will allow jquery to be updated and have the oAuth remain operational. So far no luck! :( – ChiliYago Feb 08 '13 at 19:24
  • my firewall is open. and I can make this work without updating anything after project creation. – ChiliYago Feb 09 '13 at 00:47
  • Instead of a mass package update how about individually? And update jQuery to 1.8.3. – Jasen Feb 09 '13 at 01:04