You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/includes/quickstarts/full-text-csharp.md
+31-6Lines changed: 31 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,29 @@ For the recommended keyless authentication with Microsoft Entra ID, you need to:
53
53
dotnet add package Azure.Identity
54
54
```
55
55
56
+
1. For the **recommended** keyless authentication with Microsoft Entra ID, sign in to Azure with the following command:
57
+
58
+
```console
59
+
az login
60
+
```
61
+
62
+
The sample code in this quickstart uses Microsoft Entra ID for authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with a `AzureKeyCredential` object.
63
+
64
+
#### [Microsoft Entra ID](#tab/keyless)
65
+
66
+
```csharp
67
+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
68
+
DefaultAzureCredential credential = new();
69
+
```
70
+
71
+
#### [API key](#tab/api-key)
72
+
73
+
```csharp
74
+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
75
+
AzureKeyCredential credential = new AzureKeyCredential("<Your search service admin key>");
76
+
```
77
+
---
78
+
56
79
57
80
## Create, load, and query a search index
58
81
@@ -76,17 +99,19 @@ In this section, you add code to create a search index, load it with documents,
76
99
class Program
77
100
{
78
101
static void Main(string[] args)
79
-
{
80
-
string serviceName = "<Put your search service NAME here>";
81
-
string apiKey = "<Put your search service ADMIN API KEY here>";
82
-
string indexName = "hotels-quickstart";
102
+
{
103
+
// Your search service endpoint
104
+
Uri serviceEndpoint = new Uri($"https://<Put your search service NAME here>.search.windows.net/");
105
+
106
+
// Use the recommended keyless credential instead of the AzureKeyCredential credential.
107
+
DefaultAzureCredential credential = new();
108
+
//AzureKeyCredential credential = new AzureKeyCredential("Your search service admin key");
83
109
84
110
// Create a SearchIndexClient to send create/delete index commands
85
-
Uri serviceEndpoint = new Uri($"https://{serviceName}.search.windows.net/");
86
-
AzureKeyCredential credential = new AzureKeyCredential(apiKey);
87
111
SearchIndexClient adminClient = new SearchIndexClient(serviceEndpoint, credential);
88
112
89
113
// Create a SearchClient to load and query documents
114
+
string indexName = "hotels-quickstart";
90
115
SearchClient srchclient = new SearchClient(serviceEndpoint, indexName, credential);
0 commit comments