i use to FormsAuthenticationTicket
(with form) for authorize users with [Authorize] attribute, when on IIS was allow Anonymous and Form Auths all working so good, BUT now need to switch to Windows and Form - for disable whole pages for Anonymous access. But when i try login by Windows then i have an access like a user because i use to User.Identity.IsAuthenticated for check is user login or not. How to disable Windows authority in this case.
web.config
<authentication mode="Forms">
<forms name="Auth" loginUrl="~/Account/Login" defaultUrl="~/" timeout="30"/>
</authentication>
i think about overwrite Authorize attribute but it not help with User.Identity.IsAuthenticated. ThankX
UPD: The same problem with User.Identity.Name etc...
UPD2: I think about Custom Attribute with some like this property:
public class LoggedAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return (base.AuthorizeCore(httpContext) && !IsWindows());
}
public static bool? _isWindows = null;
public static bool IsWindows()
{
if (!_isWindowsAuth.HasValue)
{
if ((HttpContext.Current != null) && HttpContext.Current.User.Identity.IsAuthenticated)
{
_isWindows = new bool?(HttpContext.Current.User is WindowsPrincipal);
}
else
{
try
{
AuthenticationSection section = (AuthenticationSection)WebConfigurationManager.OpenWebConfiguration(VirtualPathUtility.ToAbsolute("~")).GetSection("system.web/authentication");
_isWindows = new bool?(section.Mode == AuthenticationMode.Windows);
}
catch
{
_isWindows = false;
}
}
}
return _isWindows.Value;
}
}