Why is SuppressFormsAuthenticationRedirect causing a build error?

I found the SuppressFormsAuthenticationRedirect property 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 a breakpoint, checked Response in the clock window and found that it really has a property. So I tried to set it soon 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 these are pretty hacks):

 Response.StatusCode = (int)HttpStatusCode.Unauthorized; ((dynamic)Response).SuppressFormsAuthenticationRedirect = true; 
+4
source share
1 answer

Amit George suggested in the comments that this is due to the fact that .NET 4.5 was installed on my computer, but was aimed at .NET 4.0. Since .NET 4.5 is an in-place upgrade above 4.0, this DLL is used, and thus the variable had the SuppressFormsAuthenticationRedirect property at run time. The string was unsuccessful because when compiling with .NET 4, it does not know about this property.

0
source

Source: https://habr.com/ru/post/1493852/


All Articles