Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I modify the Request.Headers collection?
    text
    copied!<p>I have an ASP.NET site that uses a third-party reporting component. This component is misbehaving by throwing a <code>NullReferenceException</code> whenever the client browser is not specifying a <code>User-Agent</code> in the request headers.</p> <p>It's basically an odd scenario that I'm just trying to come up with a workaround for. I do not know who/what client is not specifying a User-Agent, which seems like bad form IMO, but we have to deal with the exceptions it is generating. I have logged a support ticket with the third-party regarding the bug in their reporting component, but I have my doubts about how fruitful that route is going to be. So my thought was just to detect when the <code>User-Agent</code> is blank and default it to something just to appease the reporting component. However, I can't seem to change anything in the Request.Headers collection. I get the following exception:</p> <pre><code>Operation is not supported on this platform. </code></pre> <p>I'm starting to believe I'm not going to be able to do this. I understand <em>why</em> ASP.NET wouldn't allow this, but I haven't come up with any other workaround.</p> <p><em>Update:</em> At penfold's suggestion, I tried to add the <code>User-Agent</code> to the <code>Request.Headers</code> collection <a href="https://stackoverflow.com/a/4098734/249144">using an <code>HttpModule</code></a>. This got it added to the <code>Headers</code> collection, but did nothing to update the <code>Request.UserAgent</code> property, which is what is causing the reporting component to fail. I've been looking through .NET Reflector to determine how that property is set so that I can update it, but I haven't come up with anything yet (there isn't just a private field that drives the property that I can find).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload