1
I have an application whose authentication is via windows login. With this class I get 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 catch the logged in user and through the corresponding view I load all the 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, as the system is, in the task registration screen the user needs to select in a dropdownlist the number of his 'Login' which is the foreign key of my table Profile to assign to him the information that is registering in the bank. How do I save this Pk_login so that the user does not have to select the login every time to enter information since automatically when he enters the system the system already recognizes the windows authentication? I’ve researched cookie and Session options but preferred another way, a way to include tasks in this same screen, rather than appearing a dropdownlist with all the logins for the user to select his, appear only his, or better yet, 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?
No. It made the same mistake as the other things I had tried " The Insert statement conflicted with the FK constraint... "
– PFVictor
Ah, so the point is you’re having an error with FK at the time of inserting. That’s it?
– Leonel Sanches da Silva
That. I’m only able to enter the login, which is my FK, manually. I want it to be inserted to fk without the user having to type it.
– PFVictor
Good! Got it! Thanks for the help!
– PFVictor