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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:55:15+00:00 2026-06-07T10:55:15+00:00

I have a page where based on certain conditions I am either doing a

  • 0

I have a page where based on certain conditions I am either doing a Response.Redirect or Server.Transfer. Now I want to add a header for both the cases. So I am doing the following

    Response.AddHeader("Vary", "User-Agent");

    if (condition) 
    {
        Server.Transfer(redirectUrl);
    }
    else
    {
        Response.Redirect(redirectUrl);
    }

Now, when the code goes via Server.Transfer code path, the Vary header is set to * whereas when it goes via Response.Redirect the header is correctly set to User-Agent.

Why does this happen and how can I set the Response Header to be same for both the cases?

  • 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-07T10:55:18+00:00Added an answer on June 7, 2026 at 10:55 am

    Andre is right that the Response object is replaced as part of Server.Transfer. If you want to make the page you’re transferring to agnostic of the parent you can probably whack the information into HttpContext.Items and then use an IHttpModule to extract the information and configure the header appropriately. Something like this would probably do the job…

    Items.Add(VaryHttpModule.Key, "User-Agent");
    
    if (condition) 
    {
        Server.Transfer(redirectUrl);
    }
    else
    {
        Response.Redirect(redirectUrl);
    }
    
    public class VaryHttpModule : IHttpModule
    {
        public const string Key = "Vary";
    
        public void Init(HttpApplication context)
        {
            context.PostRequestHandlerExecute +=
                (sender, args) =>
                    {
                        HttpContext httpContext = ((HttpApplication)sender).Context;
                        IDictionary items = httpContext.Items;
                        if (!items.Contains(Key))
                        {
                            return;
                        }
    
                        object vary = items[Key];
                        if (vary == null)
                        {
                            return;
                        }
    
                        httpContext.Response.Headers.Add("Vary", vary.ToString());
                    };
        }
    
        public void Dispose()
        {
        }
    }
    

    Cheers!

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

Sidebar

Related Questions

I want to add a certain element to a page based on if the
I have to show a page from my php script based on certain conditions.
I have a page based on a model object, and I want to have
I have a complex ICEFaces XHTML page that renders certain components conditionally, based on
I have a page based web method which works fine, using [WebMethod], i.e [WebMethod]
I have made a drag-to-trigger_event page based on this guide . I'm displaying list
I have a JavaScript based page where a grid displays all the data for
I have a page full of links that each AJAX in an article based
Hi I have a page in my java/jsp based web application which shows list
I have a page with 10 different div contents in it. Based on my

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.