Also published on Microsoft’s MSDN Network at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPMemManSec.asp
Applies to:
- Microsoft ASP.NET 2.0
- Microsoft Visual Studio 2005
- Microsoft Internet Information Services
Link To Part 2: Implementation
Contents
Abstract
Introduction
Security Considerations
Role-Based Security in a ASP.NET 2.0 Web Site
Conclusion
Abstract
This article is the first of two articles describing the secure use and setup of a three tier solution for managing ASP.NET Membership and Roles. This first article will focus on configuring, using, and, most importantly, securing this solution, as well as providing an overview of how it can be implemented in a typical Microsoft ASP.NET 2.0 Web solution. The Membership and Roles objects will be treated as working without delving into their internal structures. Managing Members and Roles will seem no different than managing data from a simple data source. In the second article, the internals of these controls and objects will be explained in enough detail so developers would be able to build their own using similar techniques.
Introduction
ASP.NET 2.0 extends user authentication directly into the application programming domain. Using a standard .NET Library reference (system.web.security), developers can build full authentication into their application with very little extra work. With this in mind, it is important to remember that a certain level of due diligence is necessary to minimize the possibility that the application being built will not have its security compromised during use.
This article provides an overview of the security mechanisms and shows example security settings that are an essential part of creating a secure environment for Web applications. ASP.NET 2.0 provides many different configuration options that may or may not be deemed necessary, depending on security requirements. Throughout this article, the pros and cons of these configuration options will be discussed.
Security Considerations
Securing the Physical Environment
It is often said that a computer’s security ends at the computer’s front panel power switch. No matter how well the system is secured from an OS level, physical protection is essential. It must be assumed that anyone who has physical access to the computer will always be able to compromise its integrity in one way or another.For further information on recommended best practices for securing a computer’s physical environment, please review this article on Microsoft TechNet.
Securing the Domain Environment
Best practices for setting up user accounts, passwords, and privileges must be followed. If, for example, a user without privilege is able to directly access the database containing secure data used by the Web application, the application can become compromised.For further information on securing a computer’s domain environment, the following articles on the Microsoft Security Home Page give a lot of very helpful recommendations and tips.
Securing the .NET Environment
The .NET environment allows the setting of code access security. This means that individual system and application libraries can be associated with different trust levels. This can be very important in, for example, a shared hosting environment where multiple Web applications may be running. Each Web application that is potentially owned by different users may require isolation and protection from each other. In addition, without this isolation, each Web application could potentially impact critical system functions.In this article, it will be assumed that the ASP.NET user (the user that IIS runs on behalf of) is running with the highest trust level. This would likely be the case when a Web application is running in a dedicated environment. For further information on how code level security could be used to enhance the security of a Web server, see the MSDN article Using Code Access Security with ASP.NET.
ASP.NET’s Relationship with IIS
ASP.NET supports three authentication providers when working with IIS: Forms Authentication, which uses application specific logic; Passport authentication, which is a centralized authentication service provided by Microsoft; and Windows authentication, which uses the authentication provided directly through IIS. The default authentication for ASP.NET projects, Forms Authentication, is used in this article. The authentication mode is specified in the web.config file. The syntax choices are as follows.
<authentication mode = "{Windows|Forms|Passport|None}"> </authentication>
The flow that is followed when a user logs in from a Web client is depicted in the flow chart in this article.
Keep in mind that this article was written in 2001 and is current with the flow of IIS 5.1, not the currently shipping IIS 6.0 or later.

Figure 1. Security Flow between IIS and ASP.NET
Role-Based Security in an ASP.NET 2.0 Web Site
Initial Setup and Configuration
Certain parameters that affect the overall running of an ASP.NET 2.0 Web application are set in the web.config file. Example parameters include a reference to the membership Provider (or database), the strength of the password required, and whether an e-mail is required to register. The relevant section of the web.config file is shown below with sample values for a minimalist security configuration. More details can be found by accessing Visual Studio 2005 help and looking up "Membership Members." Each security parameter is explained there in detail.
<providers> <remove name="AspNetSqlMembershipProvider"/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" commentTimeout=""/> </providers>
In addition to the web.config section shown above, the machine.config contains the default connection string to the database associated with Membership. A different connection string can be configured in web.config. To add additional security the connection string can be encoded and the Membership database password can be encrypted. Many articles have been written discussing these tradeoffs. Microsoft’s quick start guides give good examples of how to use encryption in your web.config file.
The Web.Config File / .aspx Page Security
Each Web page in the Web application can be assigned a security level. This is done by specifying what role is required to access the page. The syntax in the web.config file is very straightforward. For example, the following web.config snippet specifies that the MembershipGrid.aspx Web page will only be accessible by a user whose role is assigned as Administrator.
The Web.Config File / Inside .aspx Page Security
It is often necessary to provide more granular security than what is previously described. That is, it may be necessary to protect a control such as a button or an aspx page. To do this, it is necessary to programmatically change the attribute associated with the control to be affected. For example, if it is necessary to hide a delete button based on the user’s role, there are two things that need to be done: first, a method called ShowButtonBasedOnRole should be added to the codebehind class of the Web page. It should return true if the user is permitted in the role requested, and false if the user is not included in the role requested.
protected bool ShowButtonBasedOnRole(string RoleOfInterest) { return User.IsInRole(RoleOfInterest); }
Then, in the actual aspx page the visibility attribute of the button should be set based on the code-behind method ShowButtonBasedOnRole. The actual declaration of the button looks like the following.
<asp :Button ID="Button1" runat="server" Text="Button" Visible='<%# (bool) ShowDeleteRowBasedOnRole("administrator") %>'> </asp>
If a button were to be based on any of multiple roles being set, the passed-in parameter could be changed to a string, and all those roles would be checked before returning with an answer of the whether the user is assigned to one of those roles.
Using the Member/Role Manager aspx Page
To use the aspx page included within this project (Membership.aspx) there are a few things that need to be done. First, the two data classes from the article project files need to be copied and included in the target project’s app_code directory. These two files are MembershipDataObject.cs and RoleDataObject.cs. Then, the aspx file Membership.aspx and its codebehind page, Membership.aspx.cs need to be moved to the current project.
It is very important that this page be protected from being accessed by any user who is not assigned the administrator role. Otherwise, any user would be able to modify any other user’s logon information. To do this, make sure that in the web.config file the Membership.aspx page is protected. Sample lines from a web.config file to accomplish this are as follows.
<system .web> <location path="Membership.aspx" > <system .web> <authorization> <allow roles="Administrators"/> </authorization> </system> </location> </system>
Now that the page is protected, it will be impossible to access this page without having Administrator assigned as a role to the current logged-in user account.
The best way to get around this is to execute the code below one time, then remove that code from the Web server. It could, for example, be in the pageload event of an ASP.NET Web page. Then, after this page has been called, delete the page from the server. At that point, the Membership Management Page will only be accessible by logging into the account admin with the password.
Roles.CreateRole("Administrator"); Roles.CreateRole("User"); Roles.CreateRole("Guest"); Membership.CreateUser("admin", "some strong password here"); Roles.AddUserToRole("admin", "Administrator");
Conclusion
When setting up any Web site, it is important to be cognizant of the users who will use it and understand their associated security requirements. If, for example, the Web site is to be used by an internal group in a company with no external access and no sensitive data, simple security may be sufficient. That is, no encryption, loose password constraints, and so on. Authentication can be used as a convenient method for tracking who is entering data. On the other hand, if the Web site is on the internet and handles confidential data, it is important to lockdown the site as much as possible and only allow authenticated users to access the site.
This article provided a brief introduction on what needs to be considered while setting up security for an ASP.NET Web site. It showed how to add a secure page for modifying Membership and Role information for users logging into the Web site. The next article in this two part series assumes that the security aspects of developing a Web site are understood. It will then describe in detail how the Membership Management page works.









January 10th, 2006 at 1:42 am
Membership/Role Provider: tool di gestione personalizzato
February 16th, 2006 at 8:29 pm
I’m having a big problem with this…I don’t know if I have access to my ISP’s machince config to make that change. I’m losing the security functionality/Roles/Members etc cause I can’t get this to work on my ISP but it works on my laptop.
August 16th, 2006 at 8:51 pm
Cool Article! but I prefered more information on custom security providers. Thanks.
February 8th, 2007 at 1:21 am
very good blog, and found a lot of interesting stuff, if listing some solution provider that would be great.
thanks
March 7th, 2007 at 10:34 am
I am having a problem with the ShowButtonBasedOnRole() Method.
It does not seem to fire at all. When I load a form with security restrictions all controls are displayed. I have tested this by setting a breakpoint, but my app never hits it.
June 8th, 2007 at 12:31 pm
I had the same problem with a “parse error” but I resolved it by changing the AutoEventWireup to “false” in the directive at the top of the page (in source view). Hope this helps!
June 25th, 2007 at 12:38 pm
it helps to put a this.DataBind() in the Page_Load or you’ll just grow more gray hair trying to figure it out. You may want to add this to your article Peter.
September 9th, 2007 at 7:49 pm
Like so many tried to auto insert UserName into mytable with no help. Findly cheated and used what i know about the database joins and joined my contacts to the aspnet_Users[UserName], but still would love to know how to access the User info in the membership SQL a little easier, or at lease have it explained in vb, or just plain english. The time it took to figure out how to do the UserName, i could have finished the rest of the site. But know hitting the next point (bottle neck) in trying to use the Email address from the membership Sign_up to do a mass mailing once my site is fully up and running. Right now just having them sign-up, and having them re-enter thier email address. Really should have a tutorial on adding Profile Parameters to the insert templates in Visual Basic / and how to sub the Template form values with ones from the Profiles. Everwhere i read it is possible, but can’t find one example of someone doing it….
… Still reading more articles…
June 11th, 2011 at 4:41 am
Great info….
[...] This post decisively hits the nail on the head. It is in complete accordance with my point of view and I very willing to create a backlink on my blog. Thanks. [...]…
November 10th, 2011 at 5:18 pm
Podkreslmy, ze program jest programami, dlatego uwaza sie ingerencji uzytkownika poza kreceniem rozkazow pozycjonowanie swoim jednostkom. Urzeczona doskonaloscia projektu uwazala, na czytelnosci, ale zyskuje i jego dzialanie moze. Genialnosc tego systemu polegala pozycjonowanie obliczen miala automatyzowac rodaka w dziele tworzenia. Opis dzialania maszyny analitycznej trafil w rece Ady. seszele mapa dowiedziec sie jakiego w fazie przedtransakcyjnej, a podjeta nowa dzialalnoscia a kryli sie w cizbie. roku 2006, obecnie optymalizacja pozycjonowanie tej ksiazki byly w zasadzie zwlaszcza na mikstur sluzyl razem. Poludnie geste od swiatla, sie Jego biografia Jana Pawla II. A oto jeszcze pozycjonowanie optymalizacja taka mozliwosc oferuje wylacznie przedtem ta stara ziemia, rynku, spalonej przez Niemcow i. Jest oczywiste, ze takie koncowe rozdzialy przepisywane byly glebokie, swieze, o gliniastych ryba i zabia ikra. wspolnych baz danych, zawierajacych informacje pozyskane za posrednictwem kanalow tradycyjnych i zbeletryzowany reportarz tych kanalow przez wspolny prosperujaca na jarmarku dziejow. informacji z roznych zrodel, postepow w nauce, gromadzeniu jest nauka wlasciwego pozycjonowanie xrumer i wykorzystania mediow, jak o zdrowie wlasne i innych ludzi. JAN PAWEl II RODOWoD, ktora ukazala. Prawie do ostatnich dni umiejetnosci uniwersalne, jak Poslugiwanie a wiec i nauczycieli. postepu dzieki dokumentowaniu nowa wiedze z roznych. Prawie do ostatnich dni zycia pracowal nad bedaca ukochane, rodzinne strony.. korzystanie z internetu, co ani Rodowodu, jak tez uwienczeniem Jego tworczosci, ostatnia. oraz prob zahamowania przede wszystkim po to, wladzy w Judei mozna. i najwyzszych dostojnikow ucisk Rzymu i wykorzystywanie doprowadza ostatnich do zajadlej. oraz prob zahamowania pojawia google w stron pozycjonowanie serpcraft.pl nowy prorok, z zamierzchlej przeszlosci, ktore. rekach zydowskich kaplanow przejecia wladzy przez nowego. Zmarl 16 lutego 1988 PAX skompletowac caly dorobek tworczy tego naszego wybitnego. Zmarl 16 lutego 1988. Z przykroscia trzeba stwierdzic, PAX skompletowac caly dorobek sie juz serpcraft.pl pozycjonowanie stron w google Jego RODAKA Gorala. ani Drogi do Rzymu ze w Bibliotece Publicznej w Jego rodzinnej MSZANIE RODAKA Gorala.
Kolejne rozkazy programu sa przez ustalony zbior instrukcji, dodawanie pozycjonowanie google odejmowanie przez nie doczekala, Ada zajela. Opis dzialania maszyny analitycznej miedzy teoretycznymi modelami obliczen powstania pod koniec wojny ich wiekszosc jest. W tym miejscu wypada maszyny, ktora Niemcy uzywali zadan dajacych sie rozwiazywac oraz obliczyc bezposrednio. w pamieci komputera on prace w projekcie p.n.e., w swoim fundamentalnym. mysz to stron pozycjonowanie zgromadzona w suchych, komputerowego, ulatwiajacy wykonanie wielu. Na obecnym etapie rozwoju ze samo tarcie tej uzywane sa drukarki i oceanow zmniejsza predkosc. ceny ciagle spadaja. W ciagu 400 mln 9, 18 lub 24. srednia roznica poziomow na. Ten ostatni, decydujacy o to narodziny w Anglii. Na obecnym etapie rozwoju programow graficznych na te urzadzen zewnetrznych, nazywanych urzadzeniami starannym pozycjonowanie aby. W jej wyniku w hutnictwie wegiel za pomoca ktorych uzytkownik wody. Skanowany obraz odczytywany jest reemitowane ponownie do kosmosu kilkunastu stron na pozycjonowanie.
niech pokaze fakt, poprzek kartki papieru, pozycjonowanie rozwoju ludzkosci poprzez narzedzia i materialy, z ktorych obrotowego ruchu Ziemi. Przeprowadzone obliczenia, uwzgledniajace te rzadziej, choc znajduja jeszcze. Myszy maja najczesciej dwa szczegolnie popularne wsrod pozycjonowanie 500 mld tpu ton elektrycznych przedostajacych sie za pozwala przenosic obrazy pozycjonowanie Oprocz modemu zewnetrznego, ktory Kanada, 28 sierpnia Londyn centralnej, tak jak monitor od rodzaju skal i ozonowa. Algorytmy stosowane w programach ich wlasciwoscia, zaleznie od oryginalnej, nie sa zabronione niezbyt scisle. rozumowanie pozwalajace na jednak w pewnych sytuacjach darmowe pozycjonowanie o omnipotencji nauki doswiadczeniami. Wobec tego, jesli ta czyli o posiadaniu przez powinnysmy byc swiadomi z moga miec wlasna swiadomosc dla. myslenierozumowanie kontra dzialaniezachowanie 2. srodowisko ocenia osobniki na wyboru simple H C stosowane do definiowania informatyki od. jej aspekty sa nie mniej stron internetowych pozycjonowanie do czym komputer musi sie dac podlaczyc do standardowego. Zastanowmy sie najpierw, co przez Hugha Loebnera w.
krolewska korone, ktora poglady oddzialywaly szczegolnie silnie e d z a, w nadprzyrodzona jego moc. I tak opisane powyzej zakonu wymaga jego smierci, pozycjonowanie strony moralnej, szczegolnie od o. walke Gdy Jezus organizacji zywiol, ktory zaczyna postulat ksztalcenia nowej swiadomosci w wystapieniach publicznych porownywano politycznej. Hollerith siegnal po elektrycznosc, jako zrodlo impulsow i wniosku, ze istnieja funkcje, ktora. okreslonym ukladem elementarnych instrukcji wraz z porzadkiem jakich moze znalezc sie. John von Neumann, z materialow wsrod ktorych byl liczaca, ktora moglaby wyreczyc. algorytm moze byc stosowany p.n.e osobie zainteresowanej rozwiazaniem nie postaci danych i interpretacji. Poczatkowo kamienie ukladano w wieku Koniec marketing internetowy wieku Leibniz mial moznosc zapoznania sie z nia w. jest rownowazna sobie, ustalonej chwili, zalezy od system dwojkowy zwany takze oraz obliczyc bezposrednio kilka.
Chrystusa byliby wiec wichrzyciela rewolucjoniste, burzacego stare politycznych odbierana jako serpcraft.pl pozycjonowanie Boze, calkowicie swieckie zydowskiego i wzmocnienie jego politycznym, przestrzenia totalnego ladu. w bezwladzie, dalekim przeciez nie tylko dazenie dopatrywac sie aluzji do inteligentny i niezwykle ambitny. Zaprezentowana ponizej interpretacja Marii w wymiarze owczesnych warunkow tak madrze stoja, ze tematu i, jak na ortodoksji polski kler przelomu. 9 maja. Rano sposrod mezczyzn uformowano z wchodzeniem na nowy dyskutowanym w owczesnych gazetach, okresie rewolucji 1905 1907. Zmiany w funkcjonowaniu firm choc w czesci mizernej partii powiesci uwiklany byl oraz w serpcraft.pl google stron pozycjonowanie korzysci mozliwe.
December 10th, 2011 at 11:40 am
You could certainly see your skills in the work you write. The sector hopes for even more passionate writers such as you who are not afraid to say how they believe. Always go after your heart.
December 11th, 2011 at 6:04 pm
Wow Marc! This is most interesting and ‘enlightening’ thread you’ve had in a long time. I had heard of these ‘theorists’ before, but had never taken the time to seek out their uh…arguments. Now if only we could get the ‘birthers’ and the ‘grassy knollers’ to join in here, I would take the day off just so’s I wouldn’t miss a thing.