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 3210802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:37:21+00:00 2026-05-17T14:37:21+00:00

Some background. Currently have an asp.net web site which is contained on 2 web

  • 0

Some background.
Currently have an asp.net web site which is contained on 2 web servers which are load balanced i.e. web farm.

I would like to have some code which would allow me to call a particular server and execute a method on it. I WANT TO do this so that i can force all web servers to refresh their cache via a web page on the site.

Use Case is: Admin user logs into site and makes a change to a setting which is cached and then clicks “Refresh web server cache” button which then calls the update cache method on each of the servers. this is to prevent me from having to restart the app pool every time a cached setting is changed.

  • 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-05-17T14:37:22+00:00Added an answer on May 17, 2026 at 2:37 pm

    Jamiec’s answer is correct; each machine still has its own IP. I use an ASHX handler to receive the requests to reset the cache. Any machine in the web farm can initiate the request.

    This is a fairly complete example, but there are some helper methods and configuration settings that I have not included.

       <!-- 
    
        URL of user web application that can be used to clear caches.  
        Delimit multiple URLS with pipes: url1|url2|url3 
    
        -->
        <add key="UserServers" value="http://123.456.789.001/|http://123.456.789.002" />
    

    Here’s the code to actually invoke a handler on each site that performs the cache reset. I suggest using some sort of shared password between machines and separately securing the handler so that it can’t be accessed publicly.

            /// <summary>
            /// Calls for a reset of caches on one or more user sites serving reports. 
            /// Allows for multiple urls to be processed; configure the reset targets
            /// using AppSettings["UserCacheResetUrl"], delimited with pipes if there
            /// are multiple sites. 
            /// </summary>
            public static void ClearAllUserCaches()
            {
                //
                // clear local user caches
                ClearUserCaches();
    
                //
                // clear out of process user caches
    
                string[] urls = AppSettings.UserServers;
    
                for( int i = 0; i < urls.Length; i++ )
                {
                    string url = urls[i] + AppSettings.UserCacheResetPath + "&sharedPassword=" + AppSettings.SharedPassword;
    
                    WebRequest request = null;
                    HttpWebResponse response = null;
    
                    try
                    {
                        request = WebRequest.Create( url );
                        response = (HttpWebResponse)request.GetResponse();
                    }
                    catch( WebException ex )
                    {
                        Log.LogException( ex );
                    }
                    finally
                    {
                        request = null;
                    }
    
                    if( response == null || response.StatusCode != HttpStatusCode.OK )
                    {
                        if( response != null )
                        {
                            response.Close();
                            response = null;
                        }
                    }
                }
            }
    

    Handler code itself (sorry for length).

        /// <summary>
        /// Exposes an interface for trusted callers to request that this
        /// instance of the application perform an action.
        /// </summary>
        public class AdministrationRequestHandler : IHttpHandler
        {
            /// <summary>
            /// Processes an incoming request and performs an action specified via the "action"
            /// parameter passed on the query string.  Only local callers will be allowed, and
            /// only callers who pass a shared password via the "sharedPassword" query string
            /// parameter.
            /// </summary>
            /// <param name="context"></param>
            public void ProcessRequest( HttpContext context )
            {
                //
                // get the action from the query string, and check that
                // it actually contains a value.
                string action = context.Request.QueryString["action"].ToSafeString().ToUpper( CultureInfo.InvariantCulture );
    
                if( string.IsNullOrEmpty( action ) )
                {
                    //
                    // Dump out an error message and return--we can't do anything
                    // without an action and this request may have malicious
                    // origins.
                    context.Response.Write( "Missing action." );
                    return;
                }
    
                //
                // Now validate the shared password that all web applications in this
                // solution should be using.  This password will NEVER be placed on a user's
                // query string or ever passed over a public network.
                string sharedPassword = context.Request.QueryString["sharedPassword"].ToSafeString();
    
                if( string.IsNullOrEmpty( sharedPassword ) )
                {
                    context.Response.Write( "Missing shared password." );
                    return;
                }
    
                //
                // check that the shared password is actually valid
                if( sharedPassword != AppSettings.SharedPassword )
                {
                    context.Response.Write( "Invalid shared password." );
                    return;
                }
    
                //
                // perform the specified action
                if( action == "CLEAR_CACHE" )
                {
                    AppContext.ClearUserCaches();
                }
            }
    
            /// <summary>
            /// Specifies whether or not the instance is reusable.
            /// </summary>
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background : I currently have a Web Forms, ASP.NET 3.5/C# application which I'm interested
First some background, I am currently working on a relatively large Asp.Net MVC application
I have simple web application (asp.net - ajax) I have a web form which
Here's the background info first. ASP.NET 2.0 Web Site with AJAX Extensions 1.0. I
I have an ASP.NET web application, which operates just fine on IE7, IE8, IE8(Compatibility
I have an ASP.NET site and I've been doing some work refactoring code to
Some background I'm currently working on a mobile site so I keep switching user
We have a data driven ASP.NET website which has been written using the standard
I am writing an asp.net program for creating reservations in which I have a
I have an ASP.NET MVC 3 (.NET 4) web application. This app fetches data

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.