无法将lambda表达式转换为"CookieAuthenticationOptions"类型,因为它不是委托类型 [英] Cannot convert lambda expression to type 'CookieAuthenticationOptions' because it is not a delegate type

查看:125
本文介绍了无法将lambda表达式转换为"CookieAuthenticationOptions"类型,因为它不是委托类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using 1.0.1 version of asp.net core and I'm using authentication in my form.

我使用UseCookieAuthentication并给出了错误

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

Cannot convert lambda expression to type 'CookieAuthenticationOptions' because it is not a delegate type

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?}"
        );
    });
}

推荐答案

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

You need to pass in the options, not a lambda:

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

这篇关于无法将lambda表达式转换为"CookieAuthenticationOptions"类型,因为它不是委托类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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