Search code examples
asp.net.netmobilehttp-headersultidev

How do I read all X Headers in asp.net


I want to be able to identify a mobile device using some form of ID.

I read this answer: Get unique, static id from a device via web request about reading x headers in asp.net but when I list all the headers using the following code I don't get any useful x headers

    For Each var As String In Request.ServerVariables
        Response.Write("<b>" & var & "</b>: " & Request(var) & "<br>")
    Next

On my andoid device the only X header I get is HTTP_X_WAP_PROFILE


Solution

  • If you want to read HTTP headers you are going about it the wrong way. ServerVariables only holds some information from the headers.

    You should be looking at the Request.Headers property. The following code will list all headers from the HTTP Request. Presumable the "x" headers you refer to will be there..

    For Each headerName As String In Request.Headers.AllKeys
        Response.Write("<b>" & headerName & "</b>: " & Request.Headers(headerName) & "<br>")
    Next