繁体   English   中英

Facebook身份验证.NET Core

[英]Facebook Authentication .NET Core

我是Web开发的新手,因此我一直在尝试Microsoft通过其默认的.NET Core Application选项提供的模板代码。 我能够使用Azure服务成功部署网站,并将其连接到具有自己数据库的服务器。

但是,我一直在努力的一件事就是设置Facebook身份验证。 我遵循了此指南: https : //www.c-sharpcorner.com/article/authentication-using-facebook-in-asp-net-core-2-0/并能够在本地成功登录Facebook,但是当我尝试使用ConfigureServices函数中的新代码发布并转到网站,我收到HTTP 500错误。

我的网站是:vincecoreapp.azurewebsites.net

这是我插入的代码段:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();


            services.AddAuthentication().AddFacebook(facebookOptions =>
            {
                facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
                facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
            });


            // Add application services.
            services.AddTransient<IEmailSender, EmailSender>();

            services.AddMvc();
        }

任何建议都将非常有帮助,谢谢!

我的猜测是您尚未将发布的“ something.azurewebsites.net” URL添加到“ Facebook应用设置 ”中的“有效OAuth重定向设置”中

名称空间VinceCoreApp {公共类Startup {公共Startup(IConfiguration配置){Configuration =配置; }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();


        services.AddAuthentication().AddFacebook(facebookOptions =>
        {
            facebookOptions.AppId = "680347028977338";
            //Configuration["Authentication:Facebook:AppId"];
            facebookOptions.AppSecret = "fc943b8782d7d5d83a4446709f2d903a";
            //Configuration["Authentication:Facebook:AppSecret"];
        });


        // Add application services.
        services.AddTransient<IEmailSender, EmailSender>();

        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();

        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

}

这样解决了问题

暂无
暂无

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

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