File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,30 +23,20 @@ Here's an example of how to use `LocalPortFiltering` in an ASP.NET Core applicat
2323``` csharp
2424var builder = WebApplication .CreateBuilder (args );
2525
26- // Register services
27- builder .Services .AddLogging ();
28- builder .Services .AddControllers ();
29- builder .Services .AddEndpointsApiExplorer ();
30- builder .Services .AddSwaggerGen ();
31- builder .Services .AddHealthChecks ();
32- builder .Services .AddLocalPortFiltering (options =>
33- {
34- options .IncludeFailureMessage = true ; // Enable failure message
35- });
26+ // Add LocalPortFiltering service
27+ builder .Services .AddLocalPortFiltering ();
3628
3729var app = builder .Build ();
3830
39- // Configure middleware
40- app .UseSwagger ();
41- app .UseSwaggerUI ();
42- app .UseWhen (context => context .Connection .LocalPort == 5099 ,
43- appBuilder => appBuilder .UseHttpsRedirection ());
44- app .UseAuthorization ();
31+ // Use LocalPortFiltering middleware
4532app .UseLocalPortFiltering ();
4633
47- // Configure endpoints
48- app .MapHealthChecks (" /healthz" ).RequireLocalPortFiltering (allowPort : 5105 );
49- app .MapControllers ();
34+ // Define a GET endpoint with port filtering
35+ app .MapGet (" /service1" , () => " Welcome to Service 1" )
36+ .RequireLocalPortFiltering (allowPort : 5105 );
37+
38+ // Define another GET endpoint without port filtering
39+ app .MapGet (" /service2" , () => " Welcome to Service 2" );
5040
5141app .Run ();
5242```
You can’t perform that action at this time.
0 commit comments