Hello, I would like you to help me. I am new to asp.net core and I am making a login that if it is correct enter and through the database of the procedure I return the menu according to the user who enters. That is, in the database I have made in a store procedure that if you enter the user, perform different nav. I do not know if what I am doing or the structure will be fine since I am new but eager to improve.
Try to perform in session and capture in a dataset that is in my model but as no session can not be done by the model.
since I asp.net c # what I did was capture the session and the menu dynamically was graphed
What I want is to capture and in the user where you enter, the nav is dynamically plotted
This is how the store procedure throws me
for this I already managed to enter but what I can not save is that menu:
This is my driver
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login([Bind] UsuarioDetalle user)
{
ModelState.Remove("username");
ModelState.Remove("llave");
if (ModelState.IsValid)
{
string LoginStatus = objUser.ValidateLogin(user);
if (LoginStatus == "17488")
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.username)
};
ClaimsIdentity userIdentity = new ClaimsIdentity(claims, "login");
ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
await HttpContext.SignInAsync(principal);
return RedirectToAction("UserHome", "User");
}
else
{
TempData["UserLoginFailed"] = "Login Failed.Please enter correct credentials";
return View();
}
}
else
return View();
}
This is my model
private static string GetConnectionString()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
string connectionString = Configuration["ConnectionStrings:myConString"];
return connectionString;
}
string connectionString = GetConnectionString();
public string ValidateLogin(UsuarioDetalle user)
{
using (SqlConnection con = new SqlConnection(connectionString))
{
String llaveencriptada;
llaveencriptada = BankPlus.Framework.Utilitarios.EncriptadorUTF.Encriptar(user.llave);
SqlCommand cmd = new SqlCommand("Sp_RevIngreso", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@opt", 1);
cmd.Parameters.AddWithValue("@username", user.username);
cmd.Parameters.AddWithValue("@llave", llaveencriptada);
con.Open();
string result = cmd.ExecuteScalar().ToString();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
//HttpContext.Session.SetString("Menu", ds.Tables[1].Rows[0]["Menu"].ToString());
}
con.Close();
return result;
}
}