Skip to content

Commit 5396afe

Browse files
committed
fix
1 parent 796c244 commit 5396afe

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

articles/app-service/tutorial-connect-app-access-sql-database-as-user-dotnet.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ Update your application code to add the access token supplied by App Service aut
156156
> [!NOTE]
157157
> This code doesn't work locally. For more information and alternatives for local debugging, see [Debug locally when you use App Service authentication](#how-do-i-debug-locally-when-using-app-service-authentication).
158158
159-
In your `DbContext` object in *DatabaseContext.cs* or other file that configures the database context, change the default constructor to add the Microsoft Entra ID access token to the connection object.
160-
161-
```csharp
162-
public MyDatabaseContext (DbContextOptions<MyDatabaseContext> options, IHttpContextAccessor accessor)
163-
: base(options)
164-
{
165-
var conn = Database.GetDbConnection() as SqlConnection;
166-
conn.AccessToken = accessor.HttpContext.Request.Headers["X-MS-TOKEN-AAD-ACCESS-TOKEN"];
167-
}
168-
```
159+
1. In your `DbContext` object in *DatabaseContext.cs* or other file that configures the database context, change the default constructor to add the Microsoft Entra ID access token to the connection object.
160+
161+
```csharp
162+
public MyDatabaseContext (DbContextOptions<MyDatabaseContext> options, IHttpContextAccessor accessor)
163+
: base(options)
164+
{
165+
var conn = Database.GetDbConnection() as SqlConnection;
166+
conn.AccessToken = accessor.HttpContext.Request.Headers["X-MS-TOKEN-AAD-ACCESS-TOKEN"];
167+
}
168+
```
169169

170170
1. If you have a connection string called `defaultConnection` in App Service that uses SQL authentication with a username and password, use the following command to remove the connection secrets. Replace `<group-name>`, `<app-name>`, `<db-server-name>`, and `<db-name>` with your values.
171171

@@ -210,12 +210,12 @@ This command might take some time to run.
210210

211211
## Frequently asked questions
212212

213-
- [Why do I get a Login failed for user '\<token-identified principal>' error?](#why-do-i-get-a-login-failed-for-user-token-identified-principal-error)
213+
- [Why do I get a "Login failed for user '\<token-identified principal>'" error?](#why-do-i-get-a-login-failed-for-user-token-identified-principal-error)
214214
- [How do I add other Microsoft Entra users or groups in Azure SQL Database?](#how-do-i-add-other-azure-ad-users-or-groups-in-azure-sql-database)
215215
- [How do I debug locally when using App Service authentication?](#how-do-i-debug-locally-when-using-app-service-authentication)
216216
- [What happens when access tokens expire?](#what-happens-when-access-tokens-expire)
217217

218-
#### Why do I get a Login failed for user '\<token-identified principal>' error?
218+
#### Why do I get a "Login failed for user '\<token-identified principal>'" error?
219219

220220
The most common causes for a `Login failed for user '<token-identified principal>'` error are:
221221

0 commit comments

Comments
 (0)