Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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