Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

asp net core: invalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager

25.06.2018 (👁13866)

 

 

An unhandled exception occurred while processing the request.

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager

 

 

 

 

 

Solution:

You have to add the service AddIdentity in the startup.cs

 

services.AddIdentity<ApplicationUserIdentityRole>(config =>

{

    //< send Register Email >

    //*prevents registered users from logging in until their email is confirmed.

    config.SignIn.RequireConfirmedEmail = true;

    //</ send Register Email >

})

.AddEntityFrameworkStores<ApplicationDbContext>()

.AddDefaultTokenProviders();

 

 

 

 

Example of the complete startup.cs

// This method gets called by the runtime. Use this method to add services to the container.

public void ConfigureServices(IServiceCollection services)

{

    //-----------< ConfigureServices()  >-----------

    //Website_Constants.Connectionstring = Configuration["DefaultConnection"].ToString();

 

 

    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Website_Constants.Connectionstring));

 

    //--< Facebook Api >--

    services.AddIdentity<ApplicationUserIdentityRole>(config =>

    {

        //< send Register Email >

        //*prevents registered users from logging in until their email is confirmed.

        config.SignIn.RequireConfirmedEmail = true;

        //</ send Register Email >

    })

    .AddEntityFrameworkStores<ApplicationDbContext>()

    .AddDefaultTokenProviders();

 

    services.AddAuthentication().AddFacebook(facebookOptions =>

    {

        facebookOptions.AppId = Website_Constants.fp_appID;

        facebookOptions.AppSecret = Website_Constants.fp_secret;

    });

    //--</ Facebook Api >--

 

 

    // Add application services.

    services.AddTransient<IEmailSenderEmailSender>();

 

    var optRewrite = new RewriteOptions()

    .AddRedirectToHttpsPermanent();

 

 

    services.AddMvc();

 

    //-----------</ ConfigureServices() >-----------

}