private void UpdateCachePolicy(HttpCachePolicyBase cachePolicy) { cachePolicy.SetNoStore(); cachePolicy.SetValidUntilExpires(false); cachePolicy.SetRevalidation(HttpCacheRevalidation.AllCaches); cachePolicy.SetCacheability(HttpCacheability.NoCache); }
/// <summary> /// Initializes a new instance of the <see cref="FakeHttpResponse"/> class. /// </summary> /// <param name="httpOutput">The HTTP output object.</param> public FakeHttpResponse(FakeHttpOutput httpOutput = null) { this.cacheDependencies = new List<CacheDependency>(); this.cacheItemDependencies = new List<string>(); this.cookies = new HttpCookieCollection(); this.fileDependencies = new List<string>(); this.headers = new NameValueCollection(); this.log = new StringBuilder(); this.appPathModifier = p => p; this.cache = new FakeHttpCachePolicy(); this.isClientConnected = true; this.StatusCode = 200; if (httpOutput != null) { this.httpOutput = httpOutput; this.Output = httpOutput.OutputWriter; } else { this.Output = TextWriter.Null; } }
public virtual void OnAuthorization(AuthorizationContext filterContext) { SigninUser luser = UserHelper.GetSigninUser; if (luser == null) { filterContext.Result = new RedirectResult("/Sign/In?url=" + filterContext.HttpContext.Request.RawUrl); return; } _roleId = luser.RoleId.ToArray(); _namespace = filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.Namespace; _actionName = filterContext.ActionDescriptor.ActionName; _controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.Name; if (AuthorizeCore(filterContext.HttpContext)) { // ** IMPORTANT ** // Since we're performing authorization at the action level, the authorization code runs // after the output caching module. In the worst case this could allow an authorized user // to cause the page to be cached, then an unauthorized user would later be served the // cached page. We work around this by telling proxies not to cache the sensitive page, // then we hook our custom authorization code into the caching mechanism so that we have // the final say on whether a page should be served from the cache. HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache; cachePolicy.SetProxyMaxAge(new TimeSpan(0)); cachePolicy.AddValidationCallback(CacheValidateHandler, null /* data */); } else { filterContext.Result = new RedirectResult("/Sign/In?m=您没有该功能的访问权限!"); return; } }
// Methods public HttpCachePolicyBaseWrapper(HttpCachePolicyBase httpCachePolicy) { if (httpCachePolicy == null) { throw new ArgumentNullException("httpCachePolicy"); } this._httpCachePolicy = httpCachePolicy; }
public override void SetCache(HttpCachePolicyBase cache) { if (null != cache) { cache.SetCacheability(HttpCacheability.Server); cache.SetExpires(DateTime.UtcNow.AddDays(1)); } }
public void Apply(HttpCachePolicyBase policy) { policy.ThrowIfNull("policy"); if (!_hasPolicy) { return; } switch (_cacheability) { case HttpCacheability.NoCache: policy.SetCacheability(_allowsServerCaching == true ? HttpCacheability.ServerAndNoCache : HttpCacheability.NoCache); break; case HttpCacheability.Private: policy.SetCacheability(_allowsServerCaching == true ? HttpCacheability.ServerAndPrivate : HttpCacheability.Private); break; case HttpCacheability.Public: policy.SetCacheability(HttpCacheability.Public); break; } if (_noStore == true) { policy.SetNoStore(); } if (_noTransforms == true) { policy.SetNoTransforms(); } if (_clientCacheExpirationUtcTimestamp != null) { policy.SetExpires(_clientCacheExpirationUtcTimestamp.Value); } if (_clientCacheMaxAge != null) { policy.SetMaxAge(_clientCacheMaxAge.Value); } if (_allowResponseInBrowserHistory != null) { policy.SetAllowResponseInBrowserHistory(_allowResponseInBrowserHistory.Value); } if (_eTag != null) { policy.SetETag(_eTag); } if (_omitVaryStar != null) { policy.SetOmitVaryStar(_omitVaryStar.Value); } if (_proxyMaxAge != null) { policy.SetProxyMaxAge(_proxyMaxAge.Value); } if (_revalidation != null) { policy.SetRevalidation(_revalidation.Value); } }
public override void SetCache(HttpCachePolicyBase cache) { if (null == cache) { throw new ArgumentNullException("cache"); } cache.SetCacheability(HttpCacheability.NoCache); }
public HttpListenerResponseWrapper(HttpListenerResponse listenerResponse, HttpContextBase context) { _listenerResponse = listenerResponse; // _context = context; _outputStream = new MemoryStream(); _output = new StreamWriter(_outputStream); _cookies = new HttpCookieCollection(); _cache = new HttpCachePolicySimulator(context.Cache); }
public void TestSetup() { _mocks = new MockRepository(); _mockHttpContext = _mocks.StrictMock<HttpContextBase>(); _mockController = _mocks.StrictMock<ControllerBase>(); _mockResponse = _mocks.StrictMock<HttpResponseBase>(); _mockRequest = _mocks.StrictMock<HttpRequestBase>(); _mockCachePolicy = _mocks.StrictMock<HttpCachePolicyBase>(); _controllerContext = new ControllerContext(_mockHttpContext, new RouteData(), _mockController); _stubCombiner = _mocks.Stub<IIncludeCombiner>(); _mocks.ReplayAll(); _cssCombination = new IncludeCombination(IncludeType.Css, new[] { "foo.css" }, "#foo{color:red}", DateTime.UtcNow, new CssTypeElement()); }
public override void SetCache(HttpCachePolicyBase cache) { if (null == cache) { throw new ArgumentNullException("cache"); } if (!Expires.HasValue) { cache.SetCacheability(HttpCacheability.NoCache); return; } cache.SetCacheability(HttpCacheability.Public); cache.SetExpires(Expires.Value); }
public void SetUp() { _handler = new NonCacheableResponseHandler(); _httpRequest = MockRepository.GenerateMock<HttpRequestBase>(); _httpCachePolicyBase = MockRepository.GenerateMock<HttpCachePolicyBase>(); _httpResponse = MockRepository.GenerateMock<HttpResponseBase>(); _httpResponse.Stub(arg => arg.BinaryWrite(Arg<byte[]>.Is.Anything)).WhenCalled(arg => _responseWritten = true); _httpResponse.Stub(arg => arg.Cache).Return(_httpCachePolicyBase); _cachePolicy = MockRepository.GenerateMock<ICachePolicy>(); _cachePolicy.Stub(arg => arg.Clone()).Return(_cachePolicy); _response = MockRepository.GenerateMock<IResponse>(); _response.Stub(arg => arg.CachePolicy).Return(_cachePolicy); _response.Stub(arg => arg.Cookies).Return(Enumerable.Empty<Cookie>()); _response.Stub(arg => arg.GetContent()).Return(new byte[0]); _response.Stub(arg => arg.Headers).Return(Enumerable.Empty<Header>()); _response.Stub(arg => arg.StatusCode).Return(new StatusAndSubStatusCode(HttpStatusCode.OK)); _cache = MockRepository.GenerateMock<ICache>(); _result = _handler.HandleResponse(_httpRequest, _httpResponse, _response, _cache, "key"); }
public void SetUp() { _handler = new DescriptiveTextStatusCodeHandler(200); _httpRequest = MockRepository.GenerateMock<HttpRequestBase>(); _httpRequest.Stub(arg => arg.Headers).Return(new NameValueCollection()); _httpCachePolicyBase = MockRepository.GenerateMock<HttpCachePolicyBase>(); _httpResponse = MockRepository.GenerateMock<HttpResponseBase>(); _httpResponse.Stub(arg => arg.Cache).Return(_httpCachePolicyBase); _httpResponse.Stub(arg => arg.TrySkipIisCustomErrors).PropertyBehavior(); _cachePolicy = MockRepository.GenerateMock<ICachePolicy>(); _cachePolicy.Stub(arg => arg.Clone()).Return(_cachePolicy); _response = MockRepository.GenerateMock<IResponse>(); _response.Stub(arg => arg.CachePolicy).Return(_cachePolicy); _response.Stub(arg => arg.Cookies).Return(Enumerable.Empty<Cookie>()); _response.Stub(arg => arg.GetContent()).Return(new byte[0]); _response.Stub(arg => arg.Headers).Return(Enumerable.Empty<Header>()); }
void SetLongLivedCacheHeaders(HttpCachePolicyBase cache, string serverETag) { cache.SetCacheability(HttpCacheability.Public); cache.SetETag(serverETag); cache.SetExpires(DateTime.UtcNow.AddYears(1)); }
/// <summary> /// Sets the caching policy of the current response. /// </summary> /// <param name="cache">The caching policy.</param> public void SetCache(HttpCachePolicyBase cache) { this.cache = cache; }
public abstract void SetCache(HttpCachePolicyBase cache);
public void SetUp() { _httpCachePolicyBase = MockRepository.GenerateMock<HttpCachePolicyBase>(); _cachePolicy = new CachePolicy(); _cachePolicy.AllowResponseInBrowserHistory(true); _cachePolicy.ETag("etag"); _cachePolicy.NoStore(); _cachePolicy.NoTransforms(); _cachePolicy.OmitVaryStar(true); _cachePolicy.ProxyMaxAge(TimeSpan.FromHours(1)); _cachePolicy.Revalidation(HttpCacheRevalidation.AllCaches); }
/// <summary> /// Clears all headers from the current response. /// </summary> public override void ClearHeaders() { this.cache = new FakeHttpCachePolicy(); this.CacheControl = null; this.Charset = null; this.ContentType = "text/html"; this.Cookies.Clear(); this.Expires = 0; this.ExpiresAbsolute = DateTime.MinValue; this.Headers.Clear(); this.log.Clear(); this.RedirectLocation = null; this.StatusCode = 200; this.StatusDescription = null; this.SubStatusCode = 0; }
public override void SetResponseCachePolicy(HttpCachePolicyBase cache) { cache.SetCacheability(HttpCacheability.Public); cache.SetExpires(DateTime.Now.AddYears(10)); }
public void SetCache(HttpCachePolicyBase val) { _cache = val; }
public static void CacheForOneMonth(HttpCachePolicyBase cache) { cache.SetExpires(DateTime.Now.AddMonths(1)); cache.SetCacheability(HttpCacheability.Public); cache.SetValidUntilExpires(true); }
public void SetCache(HttpCachePolicyBase val) { }
/// <summary> /// 创建 ClientCachePolicyWrapper 对象 /// </summary> /// <param name="cachePolicy">要被封装的 HttpCachePolicyBase 对象</param> public ClientCachePolicyWrapper( HttpCachePolicyBase cachePolicy ) { _cachePolicy = cachePolicy; }
private void SetCache(HttpCachePolicyBase cache, System.Net.Http.Headers.CacheControlHeaderValue cacheIn) { if (cacheIn == null) return; if (cacheIn.Public) { cache.SetCacheability(HttpCacheability.Public); } if (cacheIn.Private) { cache.SetCacheability(HttpCacheability.Private); } if (cacheIn.MaxAge != null) { cache.SetMaxAge(cacheIn.MaxAge.Value); } }
public void SetUp() { _httpCachePolicyBase = MockRepository.GenerateMock<HttpCachePolicyBase>(); _httpResponseBase = MockRepository.GenerateMock<HttpResponseBase>(); _httpResponseBase.Stub(arg => arg.Cache).Return(_httpCachePolicyBase); _httpResponseBase.Stub(arg => arg.Cookies).Return(new HttpCookieCollection()); _httpResponseBase.Stub(arg => arg.Headers).Return(new NameValueCollection()); Response response = Response .OK() .ApplicationJson() .Charset("utf-8") .Content("content") .ContentEncoding(Encoding.ASCII) .Cookie(new HttpCookie("name", "value")) .Header("field", "value") .HeaderEncoding(Encoding.UTF8); response.CachePolicy.NoClientCaching(); _cacheResponse = new CacheResponse(response); _cacheResponse.WriteResponse(_httpResponseBase); }
/// <summary> /// Sets the cache policy. Unless a handler overrides /// this method, handlers will not allow a respons to be /// cached. /// </summary> /// <param name="cache">Cache.</param> public virtual void SetResponseCachePolicy(HttpCachePolicyBase cache) { cache.SetCacheability(HttpCacheability.NoCache); cache.SetNoStore(); cache.SetExpires(DateTime.MinValue); }