Output Caching In HTTP Handler And SetValidUntilExpires?

Jun 8, 2010

I'm using output caching in my custom HTTP handler in the following way:

public void ProcessRequest(HttpContext context)
{
TimeSpan freshness = new TimeSpan(0, 0, 0, 60);
context.Response.Cache.SetExpires(DateTime.Now.Add(freshness));
context.Response.Cache.SetMaxAge(freshness);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetValidUntilExpires(true);
...
}

It works, but the problem is that refreshing the page with F5 leads to page regeneration (instead of cache usage) despite of the last codeline:

context.Response.Cache.SetValidUntilExpires(true);

UPD: Seems like the cause of problem is that HTTP handler response isn't caching on server. The following code works well for web-form, but not for handler:

Response.Cache.SetCacheability(HttpCacheability.Server);

Are there some specifics of the caching the http handler response on server?

View 2 Replies


Similar Messages:

Web Forms :: Output Caching Doesn't Work With Rout Handler

Apr 22, 2010

I am trying to use output caching on my .net pages but it is not working when I use Route handlers to redirect request to actual page, but it works when I call the page directly.

also one more weird thing is that when I am debugging and using .net instance of IIS http://localhost:64293/test it is working, but when I deploy it and try to call the page it is not caching i.e. http://www.mydomain/test(but it works if I call the page directly)

I am using VS 2010, IIS 6.0, .net Framework 4

aspx page code is :

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" Title="Not Found" %>
<%@ OutputCache Duration="300" VaryByParam="*" Location ="Server" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
litPageTitle.Text = "<br/>Datetime: " + DateTime.UtcNow.ToString();
}
</script>

my global.asax.cs code is

public static void RegisterRoutes(RouteCollection routes)

View 2 Replies

How To Call Static File Handler From HTTP Handler In IIS7 And 4.0

Jan 24, 2011

I create custom HTTP handler for auto generating file and I want to tell IIS7 to serve current request like normal static file because I need to use IIS and web.config file to control compression setting and any other HTTP header of current requested file.I know. there is an internal class called StaticFileHandler in ASP.net. But I cannot access it. Or you have any other way to work like this.

View 1 Replies

HttpHandlers / Modules :: Redirect A Page From Http To Https Using Http Module Begin Request Handler?

Jul 15, 2010

i redirect a page from http to https using http module begin request handler .i am calling webservice using ajax but it is saying webserice not defined .which otherwise works fineits work fine when rediect page in page_load instead .but i need to add function for https to http in every page. i still not know why ajax is not working when i use http module for redirect

View 3 Replies

How To Pass Through Http Call With HTTP Handler

Jan 4, 2011

Background:

We are using the Facebook API and receive back URLs for profile image thumbnails. Unfortunately the protocol is restricted to just HTTP and it doesn't support HTTPS. The page on our site that hosts the thumbnails is always delivered via HTTPS, and if we use HTTP for the thumbnails the user will receive security warnings from their browser.

Solution:

Build an HTTP Handler that "passes through" the image from the Facebook URL, but allow the handler to be called via HTTPS. Before I started coding I thought I could something like this:

Response.OutputStream = WebRequest.Create(FacebookUrlForThumbnail)

but I ended up having to save the image to an object in memory than write the image to the Response.OutputStream using the image save function.

Current Code:

[Code]....

This seems inefficient but I can't find a way of using the HTTP Handler as I orginally intended. Is there way of accomplishing the goal without creating the image memory and just "passing through" the call?

View 3 Replies

MVC :: Output Caching For Several Client IP's

Apr 7, 2010

I have a page with outputcache right above the action in a controller class. What I want is to disable this outputcache for myself. Can it be done by IP?

Something like that: [OutputCache(Duration = 60, VaryByParam = "None", IgnoreIP = "100.100.100.100")]

View 6 Replies

What Is HTTP Module And HTTP Handler

Jan 20, 2010

clear my concept What is HTTP module and HTTP Handler and how does they work while page requesting???

How authentication and Authorization process work in asp.net?

View 2 Replies

MVC :: Output Caching And Query Dependency?

Sep 21, 2010

I plan to use output cache for my page and also specify sql dependencyi succeded in doing it the following way

[Code]....

Suppose if i want to implement a dependency on the sql query , i create an sqlcache dependency object and specify the sql command to it.Set the notifications .But how do i add this sqldependency to the output cache?For example: if i need to add a file dependency, i give something like Response.AddFileDependency ("filepath"); is there any similiar command available for sqldependency as well? I'm confused about this because, most of the examples i've looked into, does a cache.insert , which defeats my purpose as it's object caching and not output caching. In a nutshell, is it possible to attach a sqlcachedependency to o/p cache inside the controller action

View 3 Replies

Output Caching On Static Pages?

Jan 28, 2010

Does output caching help boost the performance of asp.net mvc pages that just consist of html, css, images, and javascript?

View 1 Replies

Web Forms :: User Control Output Caching?

Jan 11, 2010

I have a user control (say PricingGrid.ascx) which generates a pricing grid on a given product's page. I pass the user control 2 parameters : currencyId and productId. The user control has output caching specified by

[Code]....

I am adding PricingGrid.ascx to my page programatically, i.e. using LoadControl [URL]If the user changes their currency and refreshes the page, the cached version of their original currency is still showing, until the 60 seconds expires. Is there any way to force the page to check :1) Does a cached version of PricingGrid.ascx with their new currency exist?2) If so, retrieve that version, and if not, create that version.If I output all the keys in the Page.Cache object on PageLoad, I'm not seeing my user control in the output.

View 3 Replies

State Management :: Using SqlCacheDependency With Output Caching?

Apr 9, 2010

Iam adding SqlCacheDependency programmatically but Iam not able to invalidate the cache.

Iam using the following Output cache directive in the .aspx page

[Code]....

The code in the .aspx.cs file is:

[Code]....

View 1 Replies

MVC - Enabling Caching Of The Compressed Page Output?

Sep 30, 2010

I've seen a number of options for adding GZIP/DEFLATE compression to ASP.Net MVC output, but they all seem to apply the compression on-the-fly.. thus do not take advange of caching the compressed content.

Any solutions for enabling caching of the compressed page output? Preferably in the code, so that the MVC code can check if the page has changed, and ship out the precompressed cached content if not.

This question really could apply to regular asp.net as well.

View 3 Replies

Output Caching A Page Except A User Control In It?

Mar 4, 2011

I have a page which contains a user control. The structure of the page is as shown below:

Incase your not able to see the above image, check it at [URL] Now, apart from the contents of the UserControl, I'd like to cache the entire page. I tried using the OutputCache attribute in the .aspx page, however it caches the contents of the UserControl as well.

View 4 Replies

MVC :: Can't Extend The Output Caching On A Disk For A Partial View

Jan 10, 2011

Output Caching .NET 4 on any view. But I can't extend the output caching (on a disk) for a partial view(RenderAction).

View 1 Replies

MVC :: Output Caching For A View That Is Rendered From Html.RenderPartial

Jul 9, 2010

Ive tried [OutputCache] for a view that is rendered from Html.RenderPartial, but it doesn't work! It works perfectly for 'normal' views.

How do I cache output for partial view?

View 2 Replies

Caching - Controlling Output Cache Memory Usage?

May 17, 2010

I would like to use output caching with WCF Data Services and although there's nothing specifically built in to support caching, there is an OnStartProcessingRequest method that allows me to hook in and set the cacheability of the request using normal ASP.NET mechanisms.

But I am worried about the worker process getting recycled due to excessive memory consumption if large responses are cached. Is there a way to specify an upper limit for the ASP.NET output cache so that if this limit is exceeded, items in the cache will be discarded?

I've seen the caching configuration settings but I get the impression from the documentation that this is for explicit caching via the Cache object since there is a separate outputCacheSettings which has no memory-related attributes.

Here's a code snippet from Scott Hanselman's post that shows how I'm setting the cacheability of the request.

[code]....

View 1 Replies

UserControls - Programmatically Setting Output Caching Duration?

Apr 7, 2010

I want duration to be configurable from Web.config file, so user can alter the output caching after deployment.

For achieving such puropse i need quuivalent C# codebehind snippet of following ASP.NET markup?

<%@ OutputCache Duration="120" VaryByParam="CategoryName" %>

View 2 Replies

AJAX :: Enable Caching On The Script Resource Handler?

Dec 9, 2010

i try optimize my web site, i read if i enable caching on the script resource handler my site improve perfonmance

<system.web.extensions> <scripting> <scriptResourceHandler enableCompression="true" enableCaching="true"/> </scripting> </system.web.extensions>

View 1 Replies

Running IIS7 In Classic Mode Does Affect MVC Output Caching

Feb 25, 2010

I have a need to run an application in classic mode for backwards compatibility with a specific application, and am trying to understand what kind of impact that will have on the performance of an MVC application that is running on the site. If we put a few static file maps (for .js, .css, .png, etc) above the ASP.NET wildcard map to reduce the amount of processing by the ASP.NET handler, will we be approaching the integrated mode in terms of performance?

The thing i'm primarily concerned with is any effect this might have on output caching. I understand that integrated mode might (?) allow for the output cache to handle non ASP.NET content, but that isn't really a concern. We're more interested in ensuring that the MVC application has full use of the output cache. Empirically i've found that the two configurations operate on par when things go well, but if the page references resources that are not available, the integrated mode tends to fail much more quickly than the classic mode (e.g. 500 ms vs 10 seconds), reducing 'hang time' on the page load.

View 1 Replies

HttpHandlers / Modules :: Custom Handler Caching User File?

Oct 18, 2010

i have a custom handler which captures user's book mark entry. To debug this handler, i have created a file "test1.txt" in code behind which saves the user entry. After the debug, i removed the text file (test1.txt) then re-complied the web app and deployed new DLLs for the site. But, the site is still looking for test1.txt file. i dont know how to confirm if the handler is really removed from the new DLL. Also, looked at the handler code behind file and didn't find any entry with test1.txt. So,

View 1 Replies

Render Output To String - Response.Flush Breaking Page Caching

Feb 3, 2010

I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at [URL] However, I noticed that Page Caching no longer works after the first Response.Flush call.

I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set. So it seems that Response.Flush completely undermines any page caching in use. Why is this?

extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?

ASPX Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>

Code-behind (Page is Cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
Code-behind (Page is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Flush();
}
Code-behind (Page still is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Flush();
}

View 1 Replies

Intercept Output From Default Handler With Another HttpHandler?

Mar 18, 2011

I have set up an HttpHandler for *css to do some simple parsing:

<handlers>
<add name="CssHandler" verb="*" path="*.css"
type="MyApp.CssProcessor,MyApp.Assembly"/>
</handlers>

All was well until I added a resource that loads a css file dynamically, e.g.

<link rel="stylesheet" type="text/css" href="/loader.ashx/module.resource.css" >

To my surprise, things went horribly wrong. The custom http handler intercepts this, but since it's designed to just load files from the file system, it doesn't work. I realize that, technically, it matches a pattern *.css but that seems an odd behaviour, since the actual resource being requested from the web server is *.ashx and the css is only after the file path, as a parameter.

Is it possible to make the filter for a handler only apply to the actual server resource name?

Alternatively (and actually I'd like to know how to do this anyway) -- what I would really rather be doing is intercepting the output from the default css handler. That is, rather than having all my own code to actually load files from the file system in my CSS handler, it seems it would be far simpler to just take the response from the default handler and filter it. Which would have worked properly in this situation.

Finally, in either case, I'd much rather be filtering on resource MIME type text/css rather than intercepting requests by name, since what I really want to do is filter any CSS (rather than anything that happens to be named "*.css"). how to do this?

View 1 Replies

Setting Optimum Http Caching Headers And Server Params In .Net MVC And IIS 7.5?

Sep 13, 2010

I have an ASP.Net site (happens to be MVC, but that's not relevant here) with a few pages I'd like cached really well.

Specifically I'd like to achieve:

output cached on the server for 2 hours.if the file content on the server changes, that output cache should be flushed for that page
cached in the browser for 10 minutes (i.e. don't even ask the server if it's that fresh)when the browser does make an actual subsequent request, I'd like it to use etags, so that the server can return a 304 if not modified.

(note - time values above are indicative examples only)
1) and 2) I can achieve by Response.Cache.SetCacheability(HttpCacheability.Server)
I know 3) can be achieved by using max-age and cache-control:private
I can emit etags with Response.Cache.SetETagFromFileDependencies();

but I can't seem to get all of these things to work together. Here's what I have:

Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetETagFromFileDependencies();
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetMaxAge(TimeSpan.FromSeconds(60 * 10));

In particular:

can browsers do both 3) and 4) like that? When Firefox issues a new request after it expires in the local cache, it does indeed send the etag the server responded with before, but I get a 200 response.setting the variables like above, where would I set the duration of the output caching?

View 1 Replies

Trying To Write An HTTP GET Handler?

Mar 24, 2011

I'm trying to write an HTTP GET handler. The path should start with http://site/processTask and have a set of URL-encoded parameters. I have the following in my web.config

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="GET" path="processTask*" type="MyHandler.ProcessTaskHandler, MyHandler"/>
</httpHandlers>

now when I type the URL http://mysite/processTask in browser I get HTTP 404 but if I change the add verb line to the following one:

<add verb="GET" path="processTask.asmx*" type="MyHandler.ProcessTaskHandler, MyHandler"/>
and type http://mysite/ProcessTask.asmx in browser the handler is run and I get the response from the handler. What's the problem? Why is the handler run only when the path contains .asmx? How do I change web.config so that .asmx is not required?

View 1 Replies

C# - How To Configure An Http Handler In IIS 7

Nov 24, 2010

Here's what I want to do:

I've created a class library project
and this has a class implementing
the IHttpHandler interface. Let's
call this class ZipHandler. Let's
say the namespace is Zip.
I want that whenever any Http
request comes for a zip file, my
ZipHandler should handle it,
regardless of whether the request is
to an Asp.Net application or a
normal virtual directory.

Queries:

Is it possible (it should be given
the hype about integrated pipeline
etc. in IIS 7)?
How to do it?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved