我在this post找到了属性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;
答案 0 :(得分:0)