Skip to content

Commit 3f6f815

Browse files
authored
Merge pull request #189293 from Tianyun-G/update_doc
Update ASP.NET 4.x web API code samples to ASP.NET Core 6.0 web API
2 parents 6616c95 + 0f3407c commit 3f6f815

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed
15.9 KB
Loading

includes/notification-hubs-aspnet-backend-notifyusers.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ The following sections discuss the creation of a new ASP.NET WebAPI backend. Thi
1818
- **Register for notifications by using the WebAPI backend**: You add a controller to handle new registrations for a client device to receive notifications. The authenticated username is automatically added to the registration as a [tag](../articles/notification-hubs/notification-hubs-tags-segment-push-message.md).
1919
- **Send notifications to clients**: You add a controller to provide a way for users to trigger a secure push to devices and clients associated with the tag.
2020

21-
Create the new ASP.NET WebAPI backend by doing the following actions:
21+
Create the new ASP.NET Core 6.0 web API backend by doing the following actions:
2222

23-
> [!IMPORTANT]
24-
> If you are using Visual Studio 2015 or earlier, before starting this tutorial, ensure that you have installed the latest version of NuGet Package Manager for Visual Studio.
25-
>
2623
>To check, start Visual Studio. On the **Tools** menu, select **Extensions and Updates**. Search for **NuGet Package Manager** in your version of Visual Studio, and make sure you have the latest version. If your version is not the latest version, uninstall it, and then reinstall the NuGet Package Manager.
2724
2825
![Screenshot of the Extensions and Updates dialog box with the NuGet Package manage for Visual Studios package highlighted.][B4]
@@ -34,27 +31,35 @@ Create the new ASP.NET WebAPI backend by doing the following actions:
3431

3532
2. Select **Server Explorer**, and sign in to your Azure account. To create the web site resources on your account, you must be signed in.
3633

37-
3. In Visual Studio, right-click Visual Studio solution, point to **Add**, and click **New Project**.
38-
4. Expand **Visual C#**, select **Web**, and click **ASP.NET Web Application**.
34+
3. In Visual Studio's **File** menu, select **New** > **Project**.
3935

40-
5. In the **Name** box, type **AppBackend**, and then select **OK**.
36+
4. Enter **Web API** in the search box.
4137

42-
![The New Project window][B1]
38+
5. Select the **ASP.NET Core Web API** project template and select **Next**.
4339

44-
6. In the **New ASP.NET Project** window, select the **Web API** check box, and then select **OK**.
40+
6. In the **Configure your new project** dialog, name the project **AppBackend** and select **Next**.
4541

46-
![The New ASP.NET Project window][B2]
42+
7. In the **Additional information** dialog:
43+
* Confirm the **Framework** is **.NET 6.0 (Long-term support)**.
44+
* Confirm the checkbox for **Use controllers(uncheck to use minimal APIs)** is checked.
45+
* Uncheck **Enable OpenAPI support**.
46+
* Select **Create**.
4747

48-
7. In the **Configure Microsoft Azure Web App** window, select a subscription and then, in the **App Service plan** list, do either of the following actions:
48+
## Remove the WeatherForecast template files
49+
1. Remove the *WeatherForecast.cs* and *Controllers/WeatherForecastController.cs* example files from the new *AppBackend* project.
50+
2. Open *Properties\launchSettings.json*.
51+
3. Change **launchUrl** properties from **weatherforcast** to **appbackend**.
4952

50-
* Select an app service plan that you've already created.
51-
* Select **Create a new app service plan**, and then create one.
53+
In the **Configure Microsoft Azure Web App** window, select a subscription and then, in the **App Service plan** list, do either of the following actions:
54+
55+
* Select an Azure App Service plan that you've already created.
56+
* Select **Create a new app service plan**, and then create one.
5257

5358
You do not need a database for this tutorial. After you have selected your app service plan, select **OK** to create the project.
5459

55-
![The Configure Microsoft Azure Web App window][B5]
60+
![The Configure Microsoft Azure Web App window][B5]
5661

57-
If you don't see this page for configure app service plan, continue with the tutorial. You can configure it while publishing the app later.
62+
If you don't see this page for configure app service plan, continue with the tutorial. You can configure it while publishing the app later.
5863

5964
## Authenticate clients to the WebAPI backend
6065

@@ -136,7 +141,7 @@ In this section, you create a new message-handler class named **AuthenticationTe
136141

137142
> [!NOTE]
138143
> Security note: The `AuthenticationTestHandler` class does not provide true authentication. It is used only to mimic basic authentication and is not secure. You must implement a secure authentication mechanism in your production applications and services.
139-
5. To register the message handler, add the following code at the end of the `Register` method in the **App_Start/WebApiConfig.cs** class:
144+
5. To register the message handler, add the following code at the end of the `Register` method in the *Program.cs* file:
140145

141146
```csharp
142147
config.MessageHandlers.Add(new AuthenticationTestHandler());
@@ -185,13 +190,11 @@ In this section, you add a new controller to the WebAPI backend to handle reques
185190

186191
7. Next, create a new controller named **RegisterController**. In Solution Explorer, right-click the **Controllers** folder, select **Add**, and then select **Controller**.
187192

188-
8. Select **Web API 2 Controller - Empty**, and then select **Add**.
189-
190-
![The Add Scaffold window][B7]
193+
8. Select **API Controller - Empty**, and then select **Add**.
191194

192195
9. In the **Controller name** box, type **RegisterController** to name the new class, and then select **Add**.
193196

194-
![The Add Controller window][B8]
197+
:::image type="content" source="media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push8.png" alt-text="The Add Controller window." lightbox="media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push8.png":::
195198

196199
10. In RegisterController.cs, add the following `using` statements:
197200

@@ -404,7 +407,6 @@ The URL uses the web app name that you specified earlier, with the format http:/
404407
[B5]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push5.png
405408
[B6]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push6.png
406409
[B7]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push7.png
407-
[B8]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push8.png
408410
[B14]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-secure-push14.png
409411
[B15]: ./media/notification-hubs-aspnet-backend-notifyusers/publish-to-app-service.png
410412
[B16]: ./media/notification-hubs-aspnet-backend-notifyusers/notification-hubs-notify-users16.PNG

0 commit comments

Comments
 (0)