What exactly is 'UseAuthentication()' for?

后端 未结 3 2142
天命终不由人
天命终不由人 2020-12-29 18:37

I have a question regarding authentication in ASP.NET Core 2: what exactly is the call app.UseAuthentication() for?

Is it a basic prerequisite so t

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 19:18

    You do need to call it.

    UseAuthentication() is documented as:

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.authappbuilderextensions.useauthentication?view=aspnetcore-2.0

    Adds the AuthenticationMiddleware to the specified IApplicationBuilder, which enables authentication capabilities.

    It basically does this:

    IApplicationBuilder AddAuthentication(this IApplicationBuilder app) {
    
        return app.UseMiddleware();
    }
    

    ...so it's just saving you some typing and possibly some extra using imports.

    This adds an AuthenticationMiddleware instance into the process' request-handling pipeline, and this particular object adds the plumbing for authentication.

提交回复
热议问题