locked
Unable to add AddAuthentication for IIS in startup.cs RRS feed

  • Question

  • User991566988 posted

    Hi

    I'm preparing my asp.net core 2.1 project to host on the Internet.

    When I tried to put this line of code in Startup file:

    services.AddAuthentication(IISServerDefaults.AuthenticationScheme);

    This of course gives me an error of required package 'Microsoft.AspNetCore.Server.IIS', And when I try to install it as suggested it fails and gives me this error:

    Installing 'Microsoft.AspNetCore.Server.IIS' failed

    Additional information: Package restore failed. Rolling back packagae changes for '<ProjectName>'

    Why? and how to solve please?

    Wednesday, November 25, 2020 12:38 PM

All replies

  • User1120430333 posted

    You should have seen some kind of message as to why the DLL failed to install.

    Wednesday, November 25, 2020 6:30 PM
  • User991566988 posted

    Yes when I try to install it by Nuget Manager it returns thie error:

    Version conflict detected for Microsoft.AspNetCore.Authentication.Abstractions. Install/reference Microsoft.AspNetCore.Authentication.Abstractions 2.2.0 directly to project MyProject to resolve this issue. 
    MyProject -> Microsoft.AspNetCore.Server.IIS 2.2.6 -> Microsoft.AspNetCore.Authentication.Core 2.2.0 -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0) 
    MyProject -> Microsoft.AspNetCore.App 2.1.1 -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.1.1 && < 2.2.0). 

    Thursday, November 26, 2020 5:59 AM
  • User711641945 posted

    Hi musbah7.hotmail.com,

    musbah7@hotmail.com

    Additional information: Package restore failed. Rolling back packagae changes for '<ProjectName>'

    This error message means your Microsoft.AspNetCore.Server.IIS package version is higher than your project version.Your project is asp.net core 2.1 but the package version is 2.2.6.They do not match with each other.

    But another thing you need to know asp.net core 2.1 does not support windows authentication,that is to say,you could not using such code in asp.net core 2.1:

    services.AddAuthentication(IISServerDefaults.AuthenticationScheme);
    

    Reference:

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.server.iis.iisserverdefaults.authenticationscheme?view=aspnetcore-5.0#moniker-applies-to

    If you must using such authentication,please migrate from ASP.NET Core 2.1 to 2.2:

    Reference:

    https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-5.0&tabs=visual-studio

    Best Regards,

    Rena
     

    Thursday, November 26, 2020 6:57 AM