开发者

dotnetopenauth and ajax forms

开发者 https://www.devze.com 2023-01-10 08:13 出处:网络
I\'m trying implement an openId login withGoogle account together with ASP.NET MVC 2 framework and DotNetOpenAuth library.

I'm trying implement an openId login with Google account together with ASP.NET MVC 2 framework and DotNetOpenAuth library.

The following code is used to render login button:

<% using (Html.BeginForm("LogOnPostAssertion", "Authentication",开发者_开发技巧 FormMethod.Post, new { target = "_top" }))

{ %>

<%= Html.AntiForgeryToken() %>

<%= Html.Hidden("ReturnUrl", "/", new { id = "ReturnUrl" }) %>

<%= Html.Hidden("openid_openidAuthData") %>

<%= Html.OpenIdSelector(this.Page, new SelectorButton[] {

new SelectorProviderButton("https://www.google.com/accounts/o8/id", AppHelper.ImageUrl("login/google.gif")),

new SelectorOpenIdButton(Url.Content("~/Content/google.gif")) }) %>

<% } %>

</div>

</div>

<% var options = new OpenIdSelector();

options.DownloadYahooUILibrary = false;

%>

<%= Html.OpenIdSelectorScripts(this.Page, options, null) %>

This code works fine until I want to use AJAX. I don't want to reload the whole page after user was logged in. If I change Html.BeginForm with Ajax.BeginForm the authentication stops working. "LogOnPostAssertion" action is not called.

On my site the login form is opened in popup modal dialog. I want to verify user, close the dialog and refresh user status area using javascript. As example the process should be similar to the one as at http://shopping.com


Could it be because when you switched it to AJAX that you didn't preserve the POST HTTP method?

When I tried replacing the Html.BeginForm line with this one, it worked:

<% using (Ajax.BeginForm("LogOnPostAssertion", "Auth", new AjaxOptions { HttpMethod = "POST" })) { %>

By setting a breakpoint on the LogOnPostAssertion action, I saw that it did work. But the action itself would need to be adjusted to not send redirects but rather send whatever update script is appropriate.

0

精彩评论

暂无评论...
验证码 换一张
取 消