Solved

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

Posted on 2015-01-26
5
72 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A short film showing how OnPage and Connectwise integration works.

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now