title: How to implement custom proxy server?
body: <p>Ultimately, I want to <a href="https://stackoverflow.com/questions/483262/how-to-block-downloads-in-net-webbrowser-control">block downloads in .NET WebBrowser control</a>, effectively restricting it to displaying HTML, images, scripts and the like, but never, <i>ever</i> display a "Save as" dialog to the user.</p>
  
  <p>The solution proposed in an answer to that question was to hook up a custom proxy server that checks the responses and filters out anything that would lead to a download prompt. How can I implement such a proxy in my .NET application? I don't want to install third-party software or libraries.</p>
  
  <p>I found the <a href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx" rel="nofollow noreferrer">HttpListener class</a>, but I've got two problems with it:</p>
  
  <ol>
  <li>The listener requires a predefined set of prefixes that trigger it. I would, however, prefer not to hard-code host names or port numbers in my application, and keep it generic.</li>
  <li>I would have to implement the code that does the actual request myself - isn't there something that does this for me where I can simply tap into the line, examining the contents of the response and changing them as neccessary (like a request filter in J2EE does on the server side)?</li>
  </ol>
  
  <h2>Update</h2>
  
  <p>Okay, I guess I need to make this clearer: My .NET (rich client) application is being used in multiple projects which also have web-based applications. The .NET application includes a reusable, generic form with a WebBrowser control. Other developers use that form to integrate access to their web applications into the .NET application.</p>
  
  <p>I want to block downloads, so I want to have my WebBrowser form intercept all traffic and ensure that it does not lead to a "Save as" dialog. Thus...</p>
  
  <ul>
  <li>I do not know what the host names will be</li>
  <li>The WebBrowser points to the real URLs, the user clicks regular links, triggers JavaScript... all as served by the web application</li>
  <li>If the WebBrowser pointed to localhost (as proposed), I'd have to parse responses and rewrite all links so they point at localhost again, preserving the original URL. I don't want to go through that hassle.</li>
  </ul>