Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-26
5
Medium Priority
?
117 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 1000 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:Michael Fowler
Michael Fowler earned 1000 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:Michael Fowler
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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