I found the property SuppressFormsAuthenticationRedirect
on this post, but when I tried to use it:
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
Response.SuppressFormsAuthenticationRedirect = true;
I get a build error:
Error 53 'System.Web.HttpResponseBase' does not contain a definition for 'SuppressFormsAuthenticationRedirect' and no extension method 'SuppressFormsAuthenticationRedirect' accepting a first argument of type 'System.Web.HttpResponseBase' could be found (are you missing a using directive or an assembly reference?) Controllers\ErrorController.cs 39 26 Roving
So I threw in a breakpoint, inspected Response
in the watch window, and found that it does indeed have the property. So I tried setting it in the immediate with Response.SuppressFormsAuthenticationRedirect = true
which did not cause an error, and it worked as expected. So why is this a build error? I did this, just for fun, and found that it worked as expected (but this is pretty hacky):
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
((dynamic)Response).SuppressFormsAuthenticationRedirect = true;
Amith George suggested in the comments that this was because I had .NET 4.5 installed on my machine, but was targetting .NET 4.0. Because .NET 4.5 is an in-place upgrade over 4.0, that DLL was being used, and thus the variable had the SuppressFormsAuthenticationRedirect property at runtime. The build was failing properly because when compiling against .NET 4, it is not aware of that property.