I would like to use integrated authentication to access the SQL database from the web part....">

SharePoint and <identity impersonate = "false" / ">

I would like to use integrated authentication to access the SQL database from the web part. It must use the IIS application pool identifier.

By default, you will receive an error message:

System.Data.SqlClient.SqlException: Login failed for user 'SERVER\IUSR_VIRTUALMACHINE'.

Since the impersonation is set to true in web.config:

<identity impersonate="true" />

I can set it to false and the database code will work. Anonymously accessible sites will also work. Any SharePoint site that uses authentication does not work, but it is not a solution.

To solve this problem, I have to encapsulate the entire database access code to work with elevated privileges, since SharePoint does it inside? One way or another, this does not seem to be the most effective solution. This is still the way to go, just use SQL security to access databases from custom SharePoint web parts?

+3
source share
3 answers

The elements <identity />and <authentication />in the web.config file together define the account that is used to connect to SQL Server using integrated authentication.

When the configuration is <authentication mode="Windows" />configured, you send IIS to authenticate users. I assume your your web.config contains:

<authentication mode="Windows" />
<identity impersonate="true" />

IIS . <identity impersonate="true" /> IIS IIS SQL Server.

, SPSecurity.RunWithElevatedPrivileges , . , , -, : -)

+4

This is not true. Since the parameter is <identity impersonate="true" />set to true, ASP.NET/IIS will start the thread as the user who is currently registered (so that the application pool account, but the actual user registered on the website).

Something else is happening here. Could you place your connection string for the user database? (net of personal data)

0
source

Source: https://habr.com/ru/post/1711546/


All Articles