/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/DefaultBuilder/testassets/StartRequestDelegateUrlApp/Program.cs
44 строки
2 KB
Copilot
Add [Obsolete] attribute to WebHost, IWebHost, and WebHostService
15 авг 2025, 20:33
Не верифицирован
15 авг 2025, 20:33
fe0ccd9
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #pragma warning disable ASPDEPR008 // Type or member is obsolete using System; using System.Threading; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace StartRequestDelegateUrlApp; public class Program { static void Main(string[] args) { var messageSent = new ManualResetEventSlim(false); using (var host = WebHost.Start("http://127.0.0.1:0", async context => { // Respond with the ApplicationName. var env = context.RequestServices.GetRequiredService<IHostEnvironment>(); await context.Response.WriteAsync(env.ApplicationName); messageSent.Set(); })) { // Need these for test deployer to consider host deployment successful // The address written here is used by the client to send requests var addresses = host.ServerFeatures.Get<IServerAddressesFeature>().Addresses; foreach (var address in addresses) { Console.WriteLine($"Now listening on: {address}"); } Console.WriteLine("Application started. Press Ctrl+C to shut down."); // Shut down after message sent or timeout messageSent.Wait(TimeSpan.FromSeconds(30)); } } }