【问题标题】:Cannot convert lambda expression to type 'CookieAuthenticationOptions' because it is not a delegate type无法将 lambda 表达式转换为类型“CookieAuthenticationOptions”,因为它不是委托类型
【发布时间】:2017-05-31 16:08:06
【问题描述】:

我正在使用asp.net core1.0.1 版本,并且在我的表单中使用身份验证。

我使用UseCookieAuthentication,它给出了一个错误

无法将 lambda 表达式转换为类型“CookieAuthenticationOptions”,因为 它不是委托类型

Startup.cs,配置方法。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();

    app.UseApplicationInsightsRequestTelemetry();

    app.UseExceptionHandler("/Home/Error");

    app.UseApplicationInsightsExceptionTelemetry();

    app.UseStaticFiles();
    app.UseSession();

    app.UseCookieAuthentication(options =>
    {
        options.AutomaticAuthenticate = true;
        options.AutomaticChallenge = true;
        options.LoginPath = "/Home/Login";
    });

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

【问题讨论】:

  • 请详细说明您要做什么以及问题所在

标签: c# asp.net-mvc asp.net-core forms-authentication


【解决方案1】:

您需要传入选项,而不是 lambda:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AutomaticAuthenticate = true,
    AutomaticChallenge = true,
    LoginPath = "/Home/Login"
});

【讨论】:

  • 糟糕,忘记将分号改为逗号 :D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多