ASP.NET MVC 5 Web API – Controller Returns JSON DataSet with Windows Authentication

ASP.NET MVC 5 Web API – Controller Returns JSON DataSet with Windows Authentication

   \Controllers\ValuesController.cs
 
   using Newtonsoft.Json.Linq;
 
   namespace WebAPIWindowsAuthentication.Controllers
   {
      public class ValuesController : ApiController
      {
         public JObject Get()
         {
            JObject obj;
 
            if (System.Web.HttpContext.Current.User.Identity.Name.ToUpper() == @"DEISLER\LCADMIN")
            {
               obj = new JObject();
               obj.Add("User", System.Web.HttpContext.Current.User.Identity.Name);
 
               return obj;
            }else{
 
               obj = new JObject();
               obj.Add("Error", "Access Denied");
 
               return obj;
            }
 
         }
 
         … …
 
         public JObject Post()
         {
            JObject obj;
 
            if (System.Web.HttpContext.Current.User.Identity.Name.ToUpper() == @"DEISLER\LCADMIN")
            {
               obj = new JObject();
               obj.Add("User", System.Web.HttpContext.Current.User.Identity.Name);
 
               return obj;
            }
            else
            {
               obj = new JObject();
               obj.Add("Error", "Access Denied");
 
               return obj;
            }
         }
 
         … …
 
      }
   }