ASP.NET Identity – userManager.FindByName automatically adds role to user

When I validate a user the user automatically is assigned a roleId = 1 in sql table aspnetuserroles. I have this code to validate that a user token is valid: public async Task<IHttpActionResult> ValidateToken() { var principal = ClaimsPrincipal.Current; var idClaim = principal.Claims.FirstOrDefault(c => c.Type == “sub”); IdentityUser user = _userManager.FindByName(idClaim.Value); …… If the user…

Build from context in UnitOfWork pattern on ASP.Net Core

I had a Repository and UnitOfWork pattern in ASP.Net MVC project and now I want move that to my ASP.Net Core project that get context in UnitOfWork class. Context class : public class LoginContext:DbContext { public LoginContext(DbContextOptions<LoginContext> options) : base(options) { } public DbSet<Person> People { get; set; } <..other classes..> } GenericRepository : public…

Problem in downloading csv file, I have create it but not able to download in asp.net

protected void LnkExcelDownload_Click(object sender, EventArgs e) { try { string sqlConnectionString = ConfigurationManager.ConnectionStrings[“ConString”].ConnectionString; SqlConnection con = new SqlConnection(sqlConnectionString); if (con.State == ConnectionState.Closed) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(“select * from Student_Details where 1=2”, con); cmd.CommandType = CommandType.Text; da.SelectCommand = cmd; da.Fill(dt); string csv = string.Empty; foreach (DataColumn column in…