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

痞子三分冷 提交于 2019-12-24 07:57:20

问题


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


来源:https://stackoverflow.com/questions/44277688/cannot-convert-lambda-expression-to-type-cookieauthenticationoptions-because-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!