Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get value fron Response.Header

Request.Headers has a results view when looking in debug

Item (3) in the results view is the parameter I need.

Dim a = Request.Headers("GroupId").Value throws an exception:

System.InvalidCastException: 'Conversion from string "GroupId" to type 'Integer' is not valid.'

I need this value as an int as its needed for a method call.

How do I best iterate over the ResultsView to get the GroupId as an Integer?

A
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

You can check the existing Request.Headers collection.
Dim headers = Request.Headers.ToString()

Open in new window

Iterate over the request.headers to get current passing keys
Dim headers As String = ""
For Each key In Request.Headers.AllKeys
  headers &= key & "=" & Request.Headers(key) & Environment.NewLine
Next

Open in new window

Avatar of Andy Green

ASKER

I dont seem to have .AllKeys and this doesnt appear to give me the value of the single property I need.

Have found a solution thats working for now, can anyone see any issues with it?

Dim a = CInt(Request.Headers.GetValues("GroupId").FirstOrDefault())

A
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial