I am attempting to capture the current logged-in user's identity when they submit a record, but it's not working - the value for the field remains null. I think it may be due to the fact that I am using Active Directory for authentication, but I'm not sure. here' the model:
How to set current user as default value for a field in the model in MVC
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web;
namespace phaudmvc.Models
{
public class Phaud
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required, MaxLength(128), Display(Name = "Created By")]
public string PaCrtdBy { get; set; } = HttpContext.Current.User.Identity.Name;
[Display(Name = "Date Created"), Required]
public DateTime PaCrtdDt { get; set; } = DateTime.Now;
[Required, MaxLength(128), Display(Name = "Manager")]
public string Mgr { get; set; }
[Required, MaxLength(128), Display(Name = "Department")]
public string Dept { get; set; }
}
What do I need to change to get this field value to always default to the current logged-in user?