Question : Access request header in C#

I am trying to use Global.asax to do redirects  in my website. I have code that works if the page requested is a .aspx page. However when a non-existent folder  such as /products is requested, I end up on the 404 errors page.

I downloaded the ieHttpHeaders tool, and I see these headers in the  error page:

GET /products HTTP/1.1
Accept: */*
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: dev-wwwasaorg
Connection: Keep-Alive

If I could access the first line of these headers in C#, I could write the code to do what I need. However I can't seem to figure out how to access the GET.
Request.ServerVariables["ALL_HTTP"]  gives me everything after the first line. Nothing I try gives me the first line.
Any help appreciated...

Answer : Access request header in C#

When you make a request for a file (or folder) from an IIS server, IIS first checks if the file exists - if not you get the 404 errors - if it does exist it checks the extension of the file requested, and if it's .aspx IIS hands the request off to the .Net engine.

So, in your case, since the file doesn't exist, the request is never given to the .Net processing engine - thus your code will never run.  The way to get around this is to either 1) make sure the file/folder exists (even if it's basically empty) or 2) Have IIS not do any checking and just automatically give every request to .Net.

Are you on IIS 7 or 6?

Random Solutions  
 
programming4us programming4us