SuppressFormsAuthenticationRedirect
我在这篇文章中找到了该属性,但是当我尝试使用它时:
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
Response.SuppressFormsAuthenticationRedirect = true;
我得到一个构建错误:
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
于是我扔了一个断点,Response
在监视窗口中检查,发现它确实有这个属性。因此,我尝试将其设置为立即Response.SuppressFormsAuthenticationRedirect = true
不会导致错误,并且按预期工作。那么为什么这是一个构建错误呢?我这样做只是为了好玩,并发现它按预期工作(但这很hacky):
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
((dynamic)Response).SuppressFormsAuthenticationRedirect = true;