Codebureau - Matt Simner
(Not) just another .NET Developer
Thursday, June 17, 2010
Use SQL Server Trusted Connections with ASP.NET on Windows 2003 without impersonation
Access control and troubleshooting 401 errors must be one of the most annoying and recurring issues with configuring IIS. One of the problems is that it's often quite a long time between issues, and you simply forget how you solved something last time. This time I decided to write it all down as I set things up.
Target Scenario
My target scenario is a local intranet, where you want to use a 'service account' to access SQL Server, directly from your 'trusted' web application, removing the need for impersonation.
The benefits of this are of course that you can take advantage of connection pooling, but also removing the need to configure passwords in web.config for SQL users (or specific, impersonated domain users). This also removed the overhead of configuring specific domain users and their SQL Server permissions. It may also be that you just want to simplify your security model to work only on Windows authentication across the stack.
SQL Server
Create a new role in the database you're accessing, for the purposes of your application
Add your service domain user account to the role in SQL Server
Assign permissions to objects, stored procedures etc to the role (not directly to the user)
IIS/Web Site
Set up your web site/application as you would normally - one way to do things....
Create your web application root folder on the web server
Copy your files (or use your deployment tools/scripts to do this)
Create a new application pool to house your new web application (probably model this from the default web site). This is important as this is where the credentials will be set
Create the new IIS web application against the root folder (if not already done as part of step 2)
Associate the new IIS application with the new application pool
Set the ASP.NET version of your IIS application appropriate (may need to restart IIS here)
Ensure 'Integrated Security' is set ON in the Directory Security tab, and 'Anonymous' access is switched OFF
Set the application pool's 'identity' to the domain user you want to run the application (and connect to SQL Server) as
Open a command window and Go to the windows\Microsoft.NET\Framework\vXXXXX folder
run aspnet_regiis -ga <domain>\<user> to grant necessary access to the metabase etc for the service account (as per
http://msdn.microsoft.com/en-us/library/ff647396.aspx#paght000008_step3
)
In the command window go to the inetpub\adminscripts folder, and set NTAuthenticationHeaders metabase property as per instructions at
http://support.microsoft.com/kb/326985
. you can also use MetaEdit from the IIS Resource Kit to change this. If you're fully configured to use Kerberos then you can potentially skip this step, as it's all about making IIS use NTLM authentication.
Navigate to 'Web Service Extensions' in IIS Manager, and ensure that the ASP.NET version you're targeting is 'allowed'. e.g. ASP.NET 4.0 is 'prohibited' by default.
Summary
So here we've circumvented the need to use impersonation by running the ASP.NET application as a specific domain user that is configured as a SQL Server Login, and granted the right access by means of a SQL Server role. The main work is the plumbing to get IIS to work happily with that user in standard NTLM authentication (you may be able to use Kerberos depending on your network configuration).
Other background on creating service accounts can be found at
http://msdn.microsoft.com/en-us/library/ms998297.aspx
ASP.NET
|
Setup and Deployment
|
SQL Server
|
Web
posted on Thursday, June 17, 2010 11:15:53 AM (AUS Eastern Standard Time, UTC+10:00)
Comments [0]
Related posts:
Generate SQL Server Inserts from existing data - with Identity Inserts
Fixing SharePoint error: No item exists at [url]?ID=n. It may have been deleted or renamed by another user
Web Visitors vs Users, Impatient vs Bored and how they affect Website Change Management
Deploying the minimum Oracle Instant Client files with ODP.NET
SQL Server - Insert to table with ALL default values
SQL Server Stored Procedure to disable / enable all foreign keys and constraints in a database
Comments are closed.
Navigation
Codebureau Home
Matt Simner - T-Shirts, Software, Design
CodeProject Articles
Geek Casuals T-Shirts
On this page
Archive
<
September 2010
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
July, 2010 (2)
June, 2010 (2)
May, 2010 (2)
April, 2010 (3)
March, 2010 (1)
February, 2010 (2)
January, 2010 (1)
October, 2009 (2)
September, 2009 (1)
August, 2009 (1)
July, 2009 (1)
June, 2009 (3)
May, 2009 (1)
April, 2009 (3)
March, 2009 (2)
February, 2009 (2)
January, 2009 (3)
December, 2008 (4)
November, 2008 (3)
October, 2008 (4)
September, 2008 (3)
August, 2008 (3)
July, 2008 (16)
June, 2008 (10)
May, 2008 (1)
April, 2008 (6)
March, 2008 (4)
February, 2008 (7)
January, 2008 (10)
December, 2007 (2)
November, 2007 (3)
September, 2007 (3)
August, 2007 (5)
July, 2007 (5)
June, 2007 (4)
April, 2007 (1)
March, 2007 (2)
February, 2007 (2)
January, 2007 (6)
July, 2006 (1)
March, 2006 (1)
July, 2005 (2)
June, 2005 (1)
May, 2005 (3)
February, 2005 (3)
Month View
Categories
.NET Framework
Agile
Articles
ASP.NET
C#
CMS
Creative Design
CRM
dasBlog
Database
Development Process
DotNetNuke
FavPal.NET
InfoPath
IT Musings
JQuery
LINQ
Miscellaneous
Networking
Off piste
Oracle
Performance
Redbubble
Refactoring
Security
Setup and Deployment
SharePoint
SQL Server
SubVersion
Tools
Unit Testing
Usability
Visual Studio
Web
Workflow
WPF
XML
Blogroll
Brad Abrams
Charlie Poole (NUnit)
Roy Osherove
Scott Hanselman
SQL Authority - Pinal Dave