I am working on asp.net mvc 4 application. Currently the application is forms authentication enabled. But now i want to implement windows authentication in same application. The scenario is- When application will run, it will by default check for window authentication and once that is authenticated, depending upon the role of user, I need to enable forms authentication.
Following is the setting in web.config-
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Windows">
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
and following is the code in Login Controller-
[AllowAnonymous]
[HttpPost]
public JsonResult JsonLogin(User model, string returnUrl)
{
var user = HttpContext.User.Identity.Name;
if (ValidateUser(model))
{
FormsAuthentication.SetAuthCookie(model.LoginUserID, false);
return Json(new { success = true, redirect = returnUrl });
}
return Json(new { errors = GetErrorsFromModelState() });
}
but i am getting User.Identity.Name = ""; What am I missing? I want to run application on local system itself. Please tell me how to implement this scenario. Any help is appreciated! Thanks in advance!