简体   繁体   English

在asp.net Core MVC中更改Facebook身份验证按钮的布局

[英]Change layout of Facebook authentication button in asp.net Core MVC

As a semester project, friends and I are working on a Planning application in ASP.NET Core MVC. 作为一个学期的项目,我和朋友正在ASP.NET Core MVC中开发Planning应用程序。 We have enabled Facebook login, but the button is rather simple and I would like to be able to change the layout of the register-with-facebook button. 我们已经启用了Facebook登录,但是该按钮相当简单,我希望能够更改register-with-facebook按钮的布局。

We recently changed from ASP.NET Framework to Core, and in Framework I could change it in a file called _ExternalLoginListPartial.cshtml. 我们最近从ASP.NET Framework更改为Core,在Framework中,我可以在名为_ExternalLoginListPartial.cshtml的文件中对其进行更改。 I have looked around in all folders, but can't find the same or any other file related to have the same content of that file. 我在所有文件夹中四处查看,但找不到相同或任何其他与该文件具有相同内容的文件。

The way I did it in Framework were like so 我在Framework中做的方式就像这样

@foreach (AuthenticationDescription p in loginProviders)
{
    switch (@p.AuthenticationType)
    {
        case "Facebook":
            <button type="submit" class="btn btn-default facebookButton" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
            break;
           .
           .
         ..and so for other types..
    }
}

Edit 编辑

@Chris Pratt gave a good solution: here @Chris Pratt提供了一个很好的解决方案: 在这里

In the Login.cshtml from the Scaffolded items list, I made these changes: 在脚手架项目列表中的Login.cshtml中,我进行了以下更改:

@foreach (var provider in Model.ExternalLogins)
    {
    switch (@provider.DisplayName)
        {
            case "Facebook":
                  <button type="submit" class="btn btn-default facebookButton" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
                  break;
        }
     }

Identity now comes with a Default UI. 身份现在带有默认UI。 It's a Razor Class Library composed of Razor Pages and embedded static files, that's included via calling AddDefaultIdentity (which internally calls AddDefaultUI ). 这是一个由Razor页面和嵌入式静态文件组成的Razor类库,可以通过调用AddDefaultIdentity (内部调用AddDefaultUI )来包括它。 As such, nothing physically exists in your project, even though everything functions as if it was directly in your project. 这样,即使一切都像直接在您的项目中一样正常工作,项目中也没有任何物理存在。

If you want to customize this UI, you can either turn it off (by use AddIdentity instead) and build whatever you like, or (more likely) you'll want to simply scaffold in the Razor Page(s) you want to customize. 如果您想自定义此UI,则可以将其关闭(改为使用AddIdentity )并构建您喜欢的任何对象,或者(更有可能)您只需在要自定义的Razor页面中放置支架即可。 Anything actually in your project will effectively override anything coming from the Default UI. 项目中的实际内容将有效覆盖默认UI中的任何内容。

Right-click your project in the Solution Explorer and choose Add > New Scaffolded Item. 在解决方案资源管理器中右键单击您的项目,然后选择“添加”>“新建脚手架项目”。 There's a tab there for Identity, with one scaffold. 那里有一个用于标识的标签,其中有一个脚手架。 When you choose this, you'll be presented with a list of the various Razor Pages that can be scaffolded in. Select one or more you'd like to customize (or just include everything, if you like). 选择此选项时,将为您提供可以放置在其中的各种Razor页面的列表。选择一个或多个您要自定义的(如果需要,可以包括所有内容)。

For this particular change, you'll find the code in Login.cshtml . 对于此特定更改,您可以在Login.cshtml找到代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM