.Net Web Application Security
by Noffer on Aug.20, 2010, under Software Development
OBJECTIVE
Implement a standard security mechanism based on the recommended Microsoft SQL Server provider for use in a custom asp.net web application. The diagram below is helpful to understand where this component lies in the overall solution design.
This visualization shows how the security of an application can be implemented across the standard layers of an application. It’s taken from the 2nd edition of the .Net Application Architecture Guide which is a solid point of reference for implementing our Microsoft based solution.
There are two primary points of focus in securing the application: Authentication and Authorization. We need to know that users are who they say they are through authentication. We need to control access to those components that the user is granted access to via authorization. Each of these is discussed in detail below in how they can be implemented and leveraged to meet our needs.
Authentication
When configured within an application, users are prompted to authenticate. This is easily implemented in an asp.net solution via settings in the web.config. This sample code below shows the basic structure used to set the base attributes.
<authentication mode="Forms">
…
</authentication>
Clearly this is not all that is necessary, although it’s already shown that the Forms mode will be easier to use in implementing an extensible authentication process. This is the first departure from the default settings.
In order to address what underlying process is used to manage the users of the website, we need to implement a provider. In our Microsoft SQL Server based solution, it is straight forward to leverage the SQLMembershipProvider, more on this in a moment.
Authorization
Once the user has been identified as who they represent themselves to be, we inevitably will need to determine their privileges. Fortunately we have another simple structure that can be used to implement this within the web application.
<authorization>
<deny users="?"/>
<allow roles="Administrators"/>
</authorization>
This straight forward structure can be used to secure access to entire files and directories. Similar to the first provider, we can use the SQLRoleProvider to assist in our handling of user authorization.
SQL Membership and Role Providers
When we are ready to store users in our SQL database, all that needs to be done is to run the aspnet_regsql.exe installation program. What is created is a set of tables and stored procedures that are used by our providers.
The foundations are nearly in place with the creation of the database structures. To utilize them within our solution, we’ll need a few more lines of code in our web.config.
<membership defaultProvider="OurMembershipProvider">
<providers>
<clear/>
<add name="OurMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
…
/>
</providers>
</membership>
<roleManager defaultProvider="OurRoleProvider">
<providers>
<clear/>
<add name="OurRoleProvider"
type="System.Web.Security.SqlRoleProvider"
…
/>
</providers>
</roleManager>
With these settings in place we can now make use of the core methods of the providers that we are implementing. The primary Membership provider method is ValidateUser, while the Role provider would rely on using the IsUserInRole method. Various other methods can be used to manage the users and roles within the application, all relying on the standard features provided.
Should this simple approach proved incomplete, a custom provider class structure can be created to override and implement the base level behavior, and must implement a core set of methods, although the application can choose to not utilize these features.
Concerns
Three concerns with the use of a pre-defined solution as described above have been noted. This are briefly addressed below:
- There is only a practical limit to the number of roles that can be utilized, and there is not an inherent flaw in the design that limits the return of only one role. For example, the SQLMembershipProvider implements a GetRolesForUser method.
- Changes to the database structure, like moving the tables and stored procedures to a different naming convention can be achieved by implementing a pair of custom providers that would them only be similar to the methods of the SQL provide methods.
- Limitations of groups and roles are only limited to the need for complex relations of user base. The concept of a hosting domain as mentioned implies that integrated windows authentication is used. This is different than forms based authentication and be configured independently.
Conclusion
Using the simple .Net framework provided solution has several benefits. It was confirmed to meet the business requirements that have been documented outside of this analysis, minimizes custom application development and maintenance, as well as time savings.
9 Comments for this entry
3 Trackbacks / Pingbacks for this entry
-
backsplash material
October 30th, 2011 on 11:14 AMRefback blog…
takes the time to research a subject as thoroughly…
-
Shop AVON
October 30th, 2011 on 7:27 AMGreat Posts…
[...] that is the end of this post. Here you’ll find some webpages that we think you’ll appreciate, just click the links over[...]……
-
affiliate programs
January 10th, 2011 on 1:03 PMPretty good post…
I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon….

October 31st, 2011 on 5:12 PM
Have you ever thought about including a little bit more than just your articles? I mean, what you say is important and everything. But just imagine if you added some great pictures or video clips to give your posts more, “pop”! Your content is excellent but with pics and videos, this site could certainly be one of the greatest in its field. Fantastic blog!
October 31st, 2011 on 4:53 PM
Good job, post is fantastic
October 31st, 2011 on 8:21 AM
I shared this text excellently well written on digg , thanks you
October 31st, 2011 on 6:38 AM
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a little bit, but instead of that, this is magnificent blog. A great read. I will certainly be back.
October 30th, 2011 on 9:12 AM
I’m very happy with your writing capabilities as well as the web page design with your blog. Simply how much is this theme or did you customise it all on your own? Whatever it is, keep on this amazing writing, great material like these are difficult to search out
October 30th, 2011 on 4:54 AM
this is a greatblog not really what i was looking for but i found it interesting
October 30th, 2011 on 3:02 AM
Have a excellent day!. Very useful website. Nice piece of info, keep up all the work.
October 30th, 2011 on 1:47 AM
your other content : D, {thanks
August 20th, 2010 on 11:18 AM
Don’t forget about aspnet_setreg for securing .Net web applications…
http://support.microsoft.com/kb/329290