APS.NET - Windows Authentication to Access SQL Server through the Web Server - asp.net

I'm creating something like an Intranet. Users today already access directly SQL Server using Windows Authentication, where security grants are set for each user, but I want to put the ASP.NET Web Server between these users and the database. I want the IIS to pass user's windows authentication credentials (from users accessing the website) to the SQL Sever.
Conditions:
Both the Sql Server and the IIS are in the same domain.
They are in different machines.
I've found this acticle which explains how to do that, but there is a disclaimer saying that SQL and IIS must be in the same machine.
Is there some way to do that given my conditions?

The don't have to be the same machine, just make sure you have set up IIS to use Windows Authentication and also in your connection string connect as the windows user e.g.
<connectionStrings>
<add name="DatabaseConnectionName" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

Related

ASP.NET MVC app cannot connect to Azure SQL

I have created a database in Azure SQL. I have updated firewall so that my local machine and dev server can hit the database. I have tested on both machines using the credentials using SQL Server Enterprise Manager all connects fine.
When I use the same server details and credentials in my web.config, it cannot connect - I get this error:
A connection string is configured but Umbraco cannot connect to the database
The website is an umbraco cms website.
I have tried recreating the database, and also deleting reading the login and user still no joy.
<add name="umbracoDbDSN" providerName="System.Data.SqlClient" connectionString="data source={dbServer};initial catalog={databaseName};persist security info=True;user id={userID};password={userPassword};MultipleActiveResultSets=True;" />
please try this just change {} to your configuration

Accessing remote SQL Server database using Windows authenticated impersonated local account

Sorry for the long title...
Here is the situation - 2 machines:
IIS 7.5/App server Windows 2008
SQL Server 2008
The SQL Server machine has a local account SpecialUser1. This account is used as login account in SQL Server itself and has full access to the database.
The IIS machine has an identical local account SpecialUser1.
Web application is setup using Windows Authentication + ASP.NET impersonation with that SpecialUser1 defined in identity tag of web.config.
<identity impersonate="true" userName="SpecialUser1" password="SpecialPassword" />
And it's using Integrated Security access to the SQL Server, defined in a connection string:
<connectionStrings>
<add name="ConnectionString1"
connectionString="Data Source=SQLSERVER1;Initial Catalog=DB1;Integrated Security=SSPI;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Will the web application be able to get access to the SQL Server's database using that impersonated account? Meaning - are these 2 identical accounts mapped to grant access to the database ?
I relied on the information from here: http://msdn.microsoft.com/en-us/library/bsz5788z(v=vs.100).aspx
and here: http://msdn.microsoft.com/en-us/library/aa292114(v=vs.71).aspx
Thanks
I came across your question while researching windows impersonation, which has changed in MVC5. One thing that struck me is if you only have one user for accessing the database then I don't think you really need impersonation. You could just put the username/password in the connection string.
Clearly you might have other things going on that you haven't mentioned that rules this out. However, the simple answers are often the best so I thought I would add this.
PS. Be warned that windows impersonation seems to have changed in MVC5. See this question the asp.net forum for more information. I'm still researching how to do this.

What is the best authentication mode for asp.net application using SQL Server 2005 Express?

I have inherited an asp.net 2.0 application that uses a SQL Server 2005 Express database and I am grappling with the authentication mode.
I have read that windows authentication is more secure and locally that works just fine. I use the default machine account and a trusted connection in the connection string similar to :
value="trusted_connection=True;server=MYMachineName\SQLExpress;Database=DatabaseName;Pooling=false"
On the server though, I find myself having to grant more privileges to the aspnet user (execute, update) in the database and am wondering if this makes sense after all. The login verification is actually handled by the application.
Does it make more sense to set up a database user and use those credentials in the connection string? Would this be an acceptable connection string?
value="Server=myServerName\SQLExpress; Database=myDataBase; User Id=myUsername; Password=myPassword;"
If you’re not in a need for a very high security you’ll be doing just fine with sql authentication.
Try this connection string instead
<add name="connstring" connectionString="Data
Source=myServerName\SQLExpress; Initial Catalog=myDataBase;
Persist SecurityInfo=True;User ID=myUsername; Password=myPassword"
providerName="System.Data.SqlClient"/>

SQL Server integrated security without SQL Server Management Studio

I am using integrated security in an ASP.net application, the IIS and SQL Server are both hosted on the same server machine running Windows Server 2008 R2.
Is it possible to allow users to access the application from across the network AND logged in users but not let them access the database directly or via SQL Server Management Studio?
I am trying to safeguard the database access because my application is going to be deployed on the client's server at client's premises.
Here is my connection string that i am currently using
<add connectionString="Server=.\sqlexpress;Database=DB89akwA;Integrated Security=true" name="LocalSqlServer" providerName="System.Data.SqlClient" />
<add connectionString="Server=.\sqlexpress;Database=DB89akwA;Integrated Security=true" name="MainAppConnectionString" providerName="System.Data.SqlClient" />
These are the two connection strings i am currently using, one is for ASP.net Authentication and second is used by my application. These both strings are the same and of the same database.
Any suggestions?
It is not possible to 'secure' a database running on client's premises. The client's staff can get the password from the ASP.Net connection string. A domain administrator can always gain access to the database (there is an actual MSDN article describing the process: Connect to SQL Server When System Administrators Are Locked Out).
If you want to hide the Intelectual Property you feel your database has, then your only solution is to not deploy the database on the client premise (use a hosted database like SQL Azure for instance).
If you simply want to prevent the client from interfering with the database you can stipulate so in the contract. Auditing and detecting interference is possible.
Yes, that is completely possible. A Person logged in to ASP.NET using integrated security can not log in to SQL Server with the same credentials. Both are completely disconnected. It is only possible if the SQL Server has been set to allow them access.
My Piece of advice would be to create SQL Login and users, and only give them access to SQL Server. In your application, when you create the Connection String, do not set integrated security to true, and just let the user enter his Sql username and password to access the database.

hosting asp.net

I have an asp.net application and i use the login control. It uses the default aspnetdb.mdf. Everything worked fine on the local network but when i hosted the website on the internet, the login doesnt work. It gave me the error:
"Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed. "
my connection string for the database is:
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
User Instances (the AttachDBFilename part of your connection string) is a feature of SQL Server Express, and I am guessing your host services use the full version of SQL Server (that does not support that feature).
You will probably need to connect to your hosted SQL Server using SQL Server Management Studio and upload your database there. Then you will need to update your connection string to point to that server/database.

Resources