Solved

How Do You Access a Value from the Web Config using Request.Headers["RoleOfUser"]

Posted on 2015-01-26
5
93 Views
Last Modified: 2015-01-27
In my Web Config I have the following User role defined:
      <httpProtocol>
          <customHeaders>
              <add name="RoleOfUser" value="Administrator" />
          </customHeaders> 
      </httpProtocol>

Open in new window


I need to know how to retrieve the value of the User Role of Administrator using the Request.Headers["RoleOfUser"] using C# programming language.

Thanks,

Dan
0
Comment
Question by:danielolorenz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 40571792
The purpose of the <customHeader /> section is to have IIS spit out into the server response whichever headers you define. Response headers don't get sent back to the server by the client, so it really doesn't make sense why you would want to use this approach to tagging your user with a role. Aside from that, sometimes custom headers get stripped by middle-tier hardware sitting between your server and the client, so they may not be 100% reliable. Have you considered using cookies instead?
0
 
LVL 23

Assisted Solution

by:Michael74
Michael74 earned 250 total points
ID: 40572031
While @kaufmed makes an excellent point in answer to your question


using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection httpProtocolSection = config.GetSection("system.webServer/httpProtocol");
         ConfigurationElementCollection customHeadersCollection = httpProtocolSection.GetCollection("customHeaders");
         // Get value from collection here
      }

Open in new window

http://www.iis.net/configreference/system.webserver/httpprotocol/customheaders
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40572043
Michael's code is valid code, but it's not actually reading a value from the request header; rather it's reading the value directly from the config file. If that's what you want, then his code is suited for the task, but if you were expecting to get the value from the request header, which is what I thought your original question was implying, then my previous post applies.
0
 
LVL 23

Expert Comment

by:Michael74
ID: 40572053
Just reread the question and realised I got side-tracked by the Web.Config section posted and went running off down a tangent. Sorry if I confused the issue but as noted (correctly!) by @kaufmed my code will only read your config file and not the request header.
0
 

Author Closing Comment

by:danielolorenz
ID: 40573437
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question