I have an application whose authentication is via windows login. With this class I get the user login:
public static class UserDetails
{
public static string GetLogin(string userName)
{
string login = userName.Substring(userName.IndexOf(@"\") + 1);
return login;
}
In this control I get the user logged in and through the corresponding view I load all user information as soon as it enters the program.
public ActionResult Index()
{
var login = UserDetails.GetLogin(User.Identity.Name);
var perfil = db.Perfis.FirstOrDefault(x => x.Login == login);
if (perfil == null)
{
return HttpNotFound();
}
ViewBag.Id = perfil.Id;
return View(perfil);
}
Well, I have a view whose logged-in user registers information pertaining to himself as tasks he performed and date. However, in the way the system is, in the task registry screen the user needs to select in a dropdownlist the number of his 'Login' which is the foreign key of my Profile table to assign him the information he is registering with the bank. How do I save this PK_Login so that the user does not have to select the login every time it will enter an information since automatically when it enters the system the system already recognizes by the authentication of windows? I already searched the cookie and session options but preferred another way, a way in this same task inclusion screen, instead of a dropdownlist with all logins for the user to select his, appear only his, or better still , take his but hide from the screen and just point to the bank.
My view where I want to hide Profile.Login
<div class="modal-body">
<div class="row">
<div class="col-md-12">
@Html.LabelFor(model => model.Tarefa)
@Html.TextBoxFor(model => model.Tarefa, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Tarefa)
</div>
</div>
<div class="row">
<div class="col-md-6">
@Html.LabelFor(model => model.Inicio)
@Html.TextBoxFor(model => model.Inicio, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Inicio)
</div>
<div class="col-md-3">
@Html.LabelFor(model => model.Conclusão)
@Html.TextBoxFor(model => model.Conclusão, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Conclusão)
</div>
<div class="col-md-3">
@Html.LabelFor(model => model.Perfil)
@Html.DropDownListFor(model => model.Login, null, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Login)
</div>
</div>
If the only or best option is to create a cookie or session, what is the simplest way to create it?