Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:27:13+00:00 2026-06-03T20:27:13+00:00

I haven’t found a clear answer to this, so can someone help me? If

  • 0

I haven’t found a clear answer to this, so can someone help me?

If we have a URL like this

 www.website.com/results.aspx?listingtype=2&propertytype=1&location=alaska

Then we can set

 <%@ OutputCache Duration="120" VaryByParam="listingtype;propertytype;location" %>

But I use routing, so my url looks like this:

 www.website.com/buy/houses/alaska

or for example

 www.website.com/rent/condominiums/nevada

How do I use the RouteValues in VaryByParam, or can I set it from code-behind or how?
I am not using MVC, this is an ASP.NET website

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:27:14+00:00Added an answer on June 3, 2026 at 8:27 pm

    Edit: (For non ASP.NET MVC apps)

    How about this:

    Make the OutputCache definition this:

    
    <%@ OutputCache Duration="120" VaryByParam="None" VaryByCustom="listingtype;propertytype;location" %>
    

    In the Global.asax.cs add these methods:

    
    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        if (custom == "lisingtype")
        {
            return GetParamFromRouteData("listingtype", context);
        }
    
        if (custom == "propertytype")
        {
            return GetParamFromRouteData("propertytype", context);
        }
    
        if (custom == "location")
        {
            return GetParamFromRouteData("location", context);
        }
    
        return base.GetVaryByCustomString(context, custom);
    }
    
    private string GetParamFromRouteData(string routeDataKey, HttpContext context)
    {
        object value;
    
        if (!context.Request.RequestContext.RouteData.Values.TryGetValue(routeDataKey, out value))
        {
            return null;
        }
    
        return value.ToString();
    }
    

    Old Content:

    If you simply put OutputCache on your action method and make all your route parts part of your action method, something like this:

    
    [OutputCache]
    public ActionResult FindProperties(string listingtype, string propertytype, string location)
    {
    }
    

    The the framework will automatically vary the cache by these items for you (See: http://aspalliance.com/2035_Announcing_ASPNET_MVC_3_Release_Candidate_2_.4)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't seen this question anywhere else, I hope someone can help. I have
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Actually haven't found the answer for this one. What for and why do i
I haven't found this question, feel free to close if it's already up here.
I haven't found any documentation on this or seen this done before, but is
Haven't seen anything, but I have seen that you can create albums in the
Haven't found this in my search on Stackoverflow - I know I've seen a
I haven't been able to solve this prolog exercise. I was hoping someone here
I haven't found any information on MSDN regarding this problem. If we create an
Haven't seen many Geneva related questions yet, I have posted this question in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.