Any idea why am I getting this error? Error Message --> "IServiceCollection does not contain a definition for AddDefaultIdentity"
public class Program
{
public async static void Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => {
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseKestrel();
webBuilder.UseAzureAppServices();
webBuilder.UseStartup<Startup>();
})
.Build()
.RunAsync();
}
}
<div>
public class Startup</div> <div>
{</div> <div>
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)</div> <div>
{</div> <div>
Configuration
= configuration;</div> <div>
</div> <div>
HostEnvironment = hostEnvironment;</div> <div>
</div> <div>
//ConfigurationBuilder builder = new ConfigurationBuilder();</div> <div>
//Configuration = builder.Build();</div> <div>
}</div> <div>
</div> <div>
public IConfiguration Configuration { get; }</div> <div>
protected IApplicationBuilder ApplicationBuilder
{ get; private set; }</div> <div>
public IHostEnvironment HostEnvironment { get; }</div> <div>
</div> <div>
// This method gets called by the runtime. Use this method to add services to the container.</div><div>
public void ConfigureServices(IServiceCollection services)</div> <div>
{</div> <div>
// services.AddRazorPages();</div> <div>
</div> <div>
// This
is cookie authentication service.</div> <div>
// [ Old Version #3 ]</div> <div>
//services.AddIdentity<ApplicationUser, IdentityRole<Guid>>(options => {</div> <div>
// // [ Old version
#1 ]</div> <div>
// //options.Cookies.ApplicationCookie.LoginPath = new PathString("/Home/Index");</div> <div>
// //options.Cookies.ApplicationCookie.SlidingExpiration = true;</div> <div>
// //options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(this.Configuration.GetValue<int?>("Authentication:SlidingExpirationTime").Value);</div> <div>
// //options.Cookies.ApplicationCookie.AccessDeniedPath
= new PathString("/Home/AccessDenied");</div> <div>
// // [ Old version #2 ]</div> <div>
// //options.Password.RequireUppercase = false;</div> <div>
// //options.Password.RequireLowercase
= false;</div> <div>
// //options.Password.RequireNonAlphanumeric = false;</div> <div>
// //options.Password.RequireDigit = false;</div> <div>
// //options.Password.RequiredLength
= 7;</div> <div>
//})</div> <div>
// [ Old Version #3 ]</div> <div>
//.AddEntityFrameworkStores<ApplicationContext, Guid>()</div> <div>
//.AddDefaultTokenProviders();</div><div>
</div> <div>
// [ Old Version #3 - replacement ]</div> <div>
services.AddDefaultIdentity<ApplicationUser>() // "ApplicationUser" is named incorrectly, it should be "IdentityUser" instead, as per
Microsoft documentation.</div> <div>
.AddRoles<IdentityRole<Guid>>()</div> <div>
.AddEntityFrameworkStores<ApplicationContext, Guid>() // FYI - AddEntityFrameworkStores() deal with role that derives
from IdentityRole, as per documentation.</div> <div>
//.AddDefaultUI()</div> <div>
.AddDefaultTokenProviders();</div> <div>
</div><div>
// [ Old version #1 - replacement ]</div> <div>
services.ConfigureApplicationCookie(options =></div> <div>
{</div> <div>
options.LoginPath = new PathString("/Home/Index");</div><div>
options.SlidingExpiration = true;</div> <div>
options.ExpireTimeSpan = TimeSpan.FromMinutes(this.Configuration.GetValue<int?>("Authentication:SlidingExpirationTime").Value);</div> <div>
options.AccessDeniedPath = new PathString("/Home/AccessDenied");</div> <div>
});</div> <div>
</div> <div>
// [ Old version #2 - replacement ]</div> <div>
services.Configure<IdentityOptions>(options
=></div> <div>
{</div> <div>
options.Password.RequireUppercase = false;</div> <div>
options.Password.RequireLowercase = false;</div> <div>
options.Password.RequireNonAlphanumeric
= false;</div> <div>
options.Password.RequireDigit = false;</div> <div>
options.Password.RequiredLength = 7;</div> <div>
});</div> <div>
</div> <div>
services.AddMvc();</div> <div>
services.AddSession();</div> <div>
</div> <div>
//services.Configure<AuthorizationOptions>(options =></div> <div>
//{</div><div>
//});</div> <div>
}</div> <div>
</div> <div>
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.</div> <div>
public
void Configure(IApplicationBuilder app, IWebHostEnvironment env)</div> <div>
{</div> <div>
if (env.IsDevelopment())</div> <div>
{</div> <div>
app.UseDeveloperExceptionPage();</div><div>
}</div> <div>
else</div> <div>
{</div> <div>
app.UseExceptionHandler("/Error");</div> <div>
// The default HSTS value is 30 days.
You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.</div> <div>
app.UseHsts();</div> <div>
}</div> <div>
</div> <div>
app.UseHttpsRedirection();</div><div>
app.UseStaticFiles();</div> <div>
app.UseRouting();</div> <div>
app.UseAuthorization();</div> <div>
</div> <div>
app.UseEndpoints(endpoints =></div><div>
{</div> <div>
endpoints.MapRazorPages();</div> <div>
});</div> <div>
</div> <div>
// Config Exception.</div> <div>
if (env.IsDevelopment())</div><div>
app.UseDeveloperExceptionPage();</div> <div>
else</div> <div>
app.UseExceptionHandler("/Home/ErrorPage.html");</div> <div>
</div> <div>
app.UseStaticFiles();
// Note, we are not authenticating for static files if this is before them</div> <div>
app.UseSession();</div> <div>
app.UseAuthentication();</div> <div>
</div> <div>
// MVC.</div><div>
//app.UseMvc(routes => routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"));</div> <div>
}</div> <div>
}</div> <div>
}</div> <div>
</div> <div> <div>
</div><div> <div>
public class ApplicationUser : IdentityUser<Guid>, IUser</div> <div>
{</div> <div>
}</div> <div>
public interface IUser</div> <div>
{</div> <div>
}</div> <div>
</div><div>
public class ApplicationContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid></div> <div>
{</div> <div>
public ApplicationContext(DbContextOptions<ApplicationContext> options)</div> <div>
: base(options)</div> <div>
{</div> <div>
}</div> <div>
</div> <div>
protected override void OnModelCreating(ModelBuilder builder)</div> <div>
{</div> <div>
base.OnModelCreating(builder);</div> <div>
}</div> <div>
}</div> <div>
</div> <div>
</div> <div> <div>
<Project Sdk="Microsoft.NET.Sdk.Web"></div> <div>
</div> <div>
<PropertyGroup></div> <div>
<TargetFramework>netcoreapp3.1</TargetFramework></div> <div>
</PropertyGroup></div> <div>
</div> <div>
<ItemGroup></div> <div>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore"
Version="2.0.0" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="1.0.2" /></div><div>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.2" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="1.1.3" /></div> <div>
<PackageReference
Include="Microsoft.AspNetCore.Session" Version="1.1.2" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" /></div> <div>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder"
Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.3" /></div><div>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.3" /></div> <div>
</div> <div>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"
Version="3.1.3" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /></div> <div>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" /></div> <div>
</div><div>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="1.1.3" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration"
Version="1.1.2" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" /></div> <div>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /></div> <div>
<PackageReference Include="Microsoft.AspNetCore.AzureAppServicesIntegration" Version="1.0.2" /></div> <div>
</ItemGroup></div> <div>
</div><div>
</Project></div> </div> </div> <div>
</div> </div>