Asp.net mvc 2 dotnetopenauth ajax后期教程
我一直在看nerd晚餐2.0,我发现对于他们的openid,他们喜欢ajax请求。我知道你不能完全采用ajax风格(即我不能将网页粘贴在jqueryui对话框中),但你可以打开另一个窗口 看了一段时间书呆子的晚餐守则后,我似乎不明白他们是怎么做的。我想知道是否有人有关于如何实现这种ajax风格openid的分步教程Asp.net mvc 2 dotnetopenauth ajax后期教程,asp.net-mvc-2,dotnetopenauth,nerddinner,Asp.net Mvc 2,Dotnetopenauth,Nerddinner,我一直在看nerd晚餐2.0,我发现对于他们的openid,他们喜欢ajax请求。我知道你不能完全采用ajax风格(即我不能将网页粘贴在jqueryui对话框中),但你可以打开另一个窗口 看了一段时间书呆子的晚餐守则后,我似乎不明白他们是怎么做的。我想知道是否有人有关于如何实现这种ajax风格openid的分步教程 谢谢我不知道如何在NerdDinner中实现这一点,但我编写了一个分步教程来说明如何使用jQuery和ASP.NET MVC 3(Razor view engine)实现这一点: 使
谢谢我不知道如何在NerdDinner中实现这一点,但我编写了一个分步教程来说明如何使用jQuery和ASP.NET MVC 3(Razor view engine)实现这一点:
DotNetOpenAuth
模块(这将引用来自internet的正确程序集,并将必要的配置部分添加到web.config)public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
~/Views/Home/Index.cshtml
视图:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
$(function () {
$('a#btnlogin').click(function () {
// Ajaxify the btnlogin action link so that
// we popup the login form
// In this example it is a simple HTML injection
// but here you could get fancy with
// animations, CSS, jquery dialogs,
// whatever comes a designer's mind
$('#login').load(this.href);
return false;
});
});
</script>
<div>
@TempData["message"]
</div>
@if (User.Identity.IsAuthenticated)
{
<div>
Welcome @User.Identity.Name.
@using (Html.BeginForm("signout", "login", FormMethod.Post))
{
<input type="submit" value="SignOut" />
}
</div>
}
else
{
<div>
You are not authenticated.
@Html.ActionLink("Signin using OpenId", "index", "login", null, new { id = "btnlogin" })
</div>
<div id="login"></div>
}
~/Views/Login/Index.cshtml
部分视图:
@{
Layout = null;
}
<!-- Using the jquery form plugin to Ajaxify my form -->
<!-- Get from here: http://jquery.malsup.com/form/ -->
<script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('form').ajaxForm({
success: function (result) {
if (result.redirectUrl) {
// if the open id provider was found redirect
// to it so that the user can authenticate
window.location.replace(result.redirectUrl);
} else {
// there was an error => redisplay form
$('#login').html(result);
}
}
});
});
</script>
@using (Html.BeginForm())
{
@Html.Label("loginIdentifier", "OpenId: ")
@Html.TextBox("loginIdentifier", "https://www.google.com/accounts/o8/id")
@Html.ValidationMessage("loginIdentifier")
<input type="submit" value="Login" />
}
@{
布局=空;
}
$(函数(){
$('form').ajaxForm({
成功:功能(结果){
if(result.redirectUrl){
//如果找到打开的id提供程序,请重定向
//这样用户就可以进行身份验证了
window.location.replace(result.redirectUrl);
}否则{
//出现错误=>重新显示表单
$('#login').html(结果);
}
}
});
});
@使用(Html.BeginForm())
{
@Label(“loginIdentifier”,“OpenId:”)
@文本框(“loginIdentifier”https://www.google.com/accounts/o8/id")
@Html.ValidationMessage(“loginIdentifier”)
}
如果您使用的是web窗体视图引擎,则可以轻松地将该示例改编为web窗体视图引擎。我还特意留下了精美的动画和CSS内容,以展示基本内容。Wow nuget很可爱。我仍然在寻找你的解决方案,虽然没有太多的时间。嘿,我能够尝试你的代码,我非常接近我想要的期望。我希望它打开一个新窗口,而不是像在中那样替换当前窗口。所以我做了window.open(reponse.url,,'width=550;height=525');这就是nerddinner所拥有的,但从那时起,所有的视图都被加载到这个新窗口中。我不知道怎样才能阻止这一切。
@{
Layout = null;
}
<!-- Using the jquery form plugin to Ajaxify my form -->
<!-- Get from here: http://jquery.malsup.com/form/ -->
<script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('form').ajaxForm({
success: function (result) {
if (result.redirectUrl) {
// if the open id provider was found redirect
// to it so that the user can authenticate
window.location.replace(result.redirectUrl);
} else {
// there was an error => redisplay form
$('#login').html(result);
}
}
});
});
</script>
@using (Html.BeginForm())
{
@Html.Label("loginIdentifier", "OpenId: ")
@Html.TextBox("loginIdentifier", "https://www.google.com/accounts/o8/id")
@Html.ValidationMessage("loginIdentifier")
<input type="submit" value="Login" />
}