Solved

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

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

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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.

771 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

11 Experts available now in Live!

Get 1:1 Help Now