登录表单和Facebook登录MVC4 [英] Login Form and Facebook Login in MVC4

查看:98
本文介绍了登录表单和Facebook登录MVC4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey fellas,



如您所知,MVC4带有一个开箱即用的帐户控制器,可以控制登录和注册。他们还编写了外部登录的授权配置,如Facebook,Twitter等。嗯,这就是事情。他们设置它,以便在@ Html.Partial(_ LoginPartial)中编码登录/注册部分。这仅显示转到每个单独模型的登录和注册按钮。



我试图减少一步。我想将登录表单(登录模型)直接放在主页上,并在其下面添加注册表和Facebook登录按钮,以便用户可以选择填写表单并登录,使用Facebook或注册。我认为我做了那一部分,但登录表格没有登录,facebook登录给我以下错误(我知道这意味着什么,但我无法弄清楚他们想要什么来调用正确的URL



另外,在FB的位置,应该登录我用css id = facebook编码的脸书图片。除非我不显示写一些代替FB的东西,足以显示整个图像。



无法找到资源。
说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下URL并确保拼写正确。

请求的URL:/ Account / _ExternalLogin





这是我在主页中的代码



< h2>会员区< /   h2  >  
< section id = contact-form >
@using(Html.BeginForm( new {ReturnUrl = ViewBag.ReturnUrl})){
@ Html.AntiForgeryToken()
@ Html.ValidationSummary( true
< div id = membership >
< ul>
< li>
@ Html.LabelFor(m = > m.UserName)
@ Html.TextBoxFor(m = > m.UserName)
@ Html.ValidationMessageFor(m = > m.UserName)
< / li >
< ;李>
@ Html.LabelFor(m = > m.Password)
@ Html.PasswordFor(m = > m.Password)
@ Html.ValidationMessageFor(m = > m.Password)
< / li >
< ;李>
@ Html.CheckBoxFor(m = > m.RememberMe, new {@class = 复选框})
@ Html.LabelFor(m = > m.RememberMe)
< / li >
< li>< button style = float:left; margin-left:0px!important; margin-top:15px, type = submit value = < / > Log leadattribute>按钮 > < / li >
< li> @ Html.ActionLink( 注册 注册 帐户,routeValues: null ,htmlAttributes: new {id = registerLink})< / li >
< / ul >
< / div >
}
< / section >
< section class = social id = socialLoginForm >
@ Html.ActionLink( FB _ ExternalLogin 帐户 null new {id = facebook})
< / section >

@section脚本{
@ Scripts.Render( 〜/ bundles / jqueryval
}





我还包括

 @ model WebsiteManager.Models.LoginModel 

来调用登录模型



实时网站是 http://djfitz.azurewebsites.net/ [ ^ ]



我会感激帮助



ps其余的代码没有动过。它基本上和它在框中一样。

解决方案

检查完代码后,我注意到你在控制器中缺少正确的操作方法。您已添加指向某个操作的链接。该链接需要GET http方法。名称应该在开头有一个下划线。你没有你所指的行动。你应该有一个带有以下签名的方法:

 [AllowAnonymous] 
public ActionResult _ExternalLogin( )...


Hey fellas,

As you know, MVC4 comes with an "out of the box" account controller that controls the login and registration. They also coded in the Authorization configurations for External Logins such as Facebook, Twitter, etc. Well, here is the thing. They have it set up so that a login/register section is coded in a @Html.Partial("_LoginPartial"). This only shows the login and the register buttons that go to each individual model.

I was trying to cut a step out. I want to place the Login form (Login Model) directly on the home page, and add the register and facebook login buttons underneath of it so that the user can chose to fill out the form and login, use facebook, or register. I think I did that part right but the login form is not loging in, and the facebook login is giving me the following error ( which I know what it means,but I cant figure out what they want in there to call the right URL

Also, where the "FB" is, there should be login with facebook image that I coded in a css id=facebook. And it doesn''t show unless I write something in place of "FB" long enough to show the entire image.

 The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Account/_ExternalLogin



This is my code in the Home page

<h2>Members Area</h2>
            <section id="contact-form">
                @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                <div id="membership">
                    <ul>
                        <li>
                            @Html.LabelFor(m => m.UserName)
                            @Html.TextBoxFor(m => m.UserName)
                            @Html.ValidationMessageFor(m => m.UserName)
                        </li>
                        <li>
                            @Html.LabelFor(m => m.Password)
                            @Html.PasswordFor(m => m.Password)
                            @Html.ValidationMessageFor(m => m.Password)
                        </li>
                        <li>
                            @Html.CheckBoxFor(m => m.RememberMe, new { @class = "checkbox" })
                            @Html.LabelFor(m => m.RememberMe)
                        </li>
                        <li><button style="float:left; margin-left: 0px !important; margin-top:15px, " type="submit" value="Log in">Log in</button></li>
                        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" }) </li>
                    </ul>
                </div>
                }
                </section>  
                <section class="social" id="socialLoginForm">
                    @Html.ActionLink("FB", "_ExternalLogin", "Account", null, new { id = "facebook" }) 
                </section>                                        

                @section Scripts {
                    @Scripts.Render("~/bundles/jqueryval")
                }    



I am also including

@model WebsiteManager.Models.LoginModel

to call the login model

And the live site is http://djfitz.azurewebsites.net/[^]

I''ll appreciate the help

p.s. the rest of the code was untouched. It is basically the same as it came in the box.

解决方案

After examining your code, I have noticed, that you are missing the proper action method in your controller. You have put a link to an action. That link requires GET http method. And the name should have an underscore at the beginning. You don''t have the action you are referring to. You should have a method with following signature:

[AllowAnonymous]
public ActionResult _ExternalLogin()...


这篇关于登录表单和Facebook登录MVC4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆