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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:14:28+00:00 2026-05-29T23:14:28+00:00

I need to be able to append an HTTP header (or modify the user

  • 0

I need to be able to append an HTTP header (or modify the user agent string) sent by most HTTP requests leaving a PC.

By most, I mean anything inside Internet Explorer, as well as anything coming from a .NET application.

I’ve already acoomplished the Internet Explorer side of things by writing a BHO, but that BHO won’t intercept requests made by ClickOnce controls loaded into IE, which is another requirement.

The .NET applications in my case are all using WebRequest.Create to made their requests.

Is this possible? I’m hoping I get inject some code into the System.Net stack someplace.

A proxy was one possibility, but it has proven difficult to create a proxy that doesn’t perform like hell. HTTPS traffic is another problem.

  • 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-29T23:14:31+00:00Added an answer on May 29, 2026 at 11:14 pm

    Ok. I figured this out.

    I created a custom web request module that explicitly sets the user agent of the HttpWebRequest before it’s returned by the WebRequest.Create factory.

    First, create a class that implemented IWebRequestCreate:

    public class CustomHttpRequestCreator : IWebRequestCreate
    {
        public CustomHttpRequestCreator(){}
    
        public WebRequest Create(Uri uri)
        {
            HttpWebRequest webRequest = Activator.CreateInstance(typeof(HttpWebRequest),
                                            BindingFlags.CreateInstance | BindingFlags.Public |
                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                            null, new object[] { uri, null }, null) as HttpWebRequest;
    
            webRequest.UserAgent = "OMG IT WORKED!";
            return webRequest;
        }
    }
    

    You’ll need to sign this assembly and add it to the GAC.

    Now in the machine.config on your machine, add the following configuration section:

    <system.net>
        <webRequestModules>
            <remove prefix="http:"/>
            <remove prefix="https:"/>
            <add prefix="http:" type="HttpWebRequestTest.CustomHttpRequestCreator, HttpWebRequestTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4ba7a6b9db5020b7" />
            <add prefix="https:" type="HttpWebRequestTest.CustomHttpRequestCreator, HttpWebRequestTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4ba7a6b9db5020b7" />
        </webRequestModules>
    </system.net>   
    

    Now whenever somebody calls WebRequest.Create, they’ll get an HttpWebRequest with the user agent string already set.


    I also attempted to create a custom class that inherited from HttpWebRequest, but this was tricky because there was no default public constructor. The only public contructor was an obsolete implementation of ISerializable.

    I successfully got my dervied class to be used with the ISerializable constructor, but the resulting “pseudo-hydrated” object wasn’t in a valid state, likely due to the fact the ISerializable implementation is obsolete and hasn’t been maintained by Microsoft.

    Still, it’s possible that one could make this work if they investigate the errors encountered when using it in a bit more detailed. Specifically, there are issues with ServicePoint related access. Using reflection, one might be able to get the thing working. Here is my implementation for reference:

    public class CustomHttpWebRequest : HttpWebRequest
    {
        public CustomHttpWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) { }
    
        internal CustomHttpWebRequest(Uri uri) : base(BuildSerializationInfo(uri), new StreamingContext())
        {
            this.UserAgent = "OMG IT WORKED! (Constructor)";
        }
    
        private static SerializationInfo BuildSerializationInfo(Uri uri)
        {
            HttpWebRequest webRequest = Activator.CreateInstance(typeof(HttpWebRequest),
                                            BindingFlags.CreateInstance | BindingFlags.Public |
                                            BindingFlags.NonPublic | BindingFlags.Instance,
                                            null, new object[] { uri, null }, null) as HttpWebRequest;
    
            var serializationInfo = new SerializationInfo(typeof(HttpWebRequest), new System.Runtime.Serialization.FormatterConverter());
            ((ISerializable)webRequest).GetObjectData(serializationInfo, new StreamingContext());
            return serializationInfo;
        }
    
        public override WebResponse GetResponse()
        {
            this.UserAgent = "OMG IT WORKED!";
            return base.GetResponse();
        }
    
        public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
        {
            this.UserAgent = "OMG IT WORKED ASYNC!";
            return base.BeginGetResponse(callback, state);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to get a list of the groups a user
I am using EF Feature CTP5 and need to be able to just append
I need to be able to convert user input to [a-z] roman characters ONLY
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to create basic MS Project items (tasks, projects, resources,
I need to be able to get at the full URL of the page
I need to be able to merge two (very simple) JavaScript objects at runtime.
I need to be able to load the entire contents of a text file
I need to be able to quickly convert an image (inside a rails controller)

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.