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.
- Create new MVC4 Inernet Application
- In Package Manager console execute: update-package
- 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.)
- 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'
- Click the login link on home page
- Click the Google Button
at this point I get this error:
ProtocolException was unhandled by user code
No OpenID endpoint found
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
livecurrently is the methodon.However the syntax is a bit different, since the method has more uses on jQuery.
modify the call to
livewith a call toon.For
onact like we happen to liveon3 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:
I moved the selector to the second parameter of
onand 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:
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