Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to create persistent header with every call

$
0
0

Here is my problem. I need to have a persistent header value added to each request that hits our IIS server. The value will be used by our 3 party application.

We have successfully used a cookie to do this but we would rather use a header value instead of the cookie.  Presently, we are routing all calls to hit our front end portal login.aspx page.  We were hoping to add to the request header at that time.  But I believe it is to late by then.  What I am doing is parsing a header value coming from a reverse proxy server.  I thought about this problem also by using aiis inbound rule rewrite but I am stumped on getting a header variable parsing it and creating another header value with the necessary information.

What I have tried thus far?

1.  I've tried to add an header to the header collection in the global.aspx.cs in the Application_AuthenticationRequest.  In this I was able to add to the header collection but on subsequent requests these header values are not present.

2.  I created a IHttpModule header module.  Once again the header values are not persistent on every call.  I used the following code block to try to accomplish this task.  I did this in the Application_PresendRequest.  The Application_EndRequest has always provided an error for me.

NameValueCollection headers = HttpContext.Current.Request.Headers;
            //get a type
            Type t = headers.GetType();
            //get the property
            PropertyInfo p = t.GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
            //unset readonly
            p.SetValue(headers, false, null);

            if (HttpContext.Current.Request.Headers["testval"] != null)
            {
                //add a header
                headers.Remove("testval");
            }
            else
            {
                headers.Add("testval", "00000");
            }

What is the best way to accomplish this task?  Are there any ideas as to how to make this happen.

Thanks for any help.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>