Cannot convert lambda expression to type 'Cook

2019-07-22 15:01发布

问题:

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

I use UseCookieAuthentication and its gives an error

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

In the Startup.cs, configure method.

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

回答1:

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

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