views:

66

answers:

1

Hi folks,

I've got a website that has a number of host headers. Depending on the host header, the results are different - both visually (theme'd) and data.

So lets imagine i have a website called 'Foo' - that returns search results (original, eh?).

Now, the same code runs both sites. It is physically the same server/website (using Host Headers) :-

  1. www.foo.com
  2. www.foo.com.au

Now, if i goto '.com', the site is theme'd in blue. if i goto the '.com.au' site, it's theme'd in red.

And the data is different for the same search result, based on the host name (ie. us results for .com, au results for .com.au)

SO .. if i wish to use OutputCaching .. can this be handled / differ by the host name?

I don't want to have the first person goto the .com site .. grab the results ... and the a second person goto my .com.au .. same search data .. and get the theme and results for the .com site.

Possible?

+3  A: 

Check out the VaryByCustom parameter of the OutputCache directive.

To define what happens when VaryByCustom is called, you need to override the method GetVaryByCustomString:

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if(custom == "Your_Custom_Value")
    {
        // Do some validation.
        // Return a string for say, .com, or .com.au

    }
    return String.Empty;
}

The key is to return a string value for each instance you want to cache. In your case, your overrided method would need to strip the ".com" or ".com.au" part from the URL and return it. Each different value produces a different cache.

HTH

Richard
Dude -that really does help. If anything, I can now spend some time researching this. I'll return in a week or so with some answers when I next get some time. But seriously - thanks for the idea .. it's very very very helpful!!
Pure.Krome
Glad that this has been helpful. Just thinking, you might want to use HttpContext.Current.Request.Url.Host to determine the host name that the user is using to connect to your site. You can then search that string for the substring '.com' or '.com.au' and just return it - ASP.NET will do the rest.
Richard
Pure.Krome