Skip to content

Instantly share code, notes, and snippets.

@SibeeshVenu
Last active August 12, 2023 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SibeeshVenu/9412bd9798bf78fc3d1ae62abdc61e50 to your computer and use it in GitHub Desktop.
Save SibeeshVenu/9412bd9798bf78fc3d1ae62abdc61e50 to your computer and use it in GitHub Desktop.
WeatherForecastController.cs with IpActionFilter ServiceFilter
using DotNetIpFilter.Services;
using Microsoft.AspNetCore.Mvc;
namespace DotNetIpFilter.Controllers
{
[ApiController]
[Route("[controller]")]
[ServiceFilter(typeof(IpActionFilter))]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
this.logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
this.logger.LogInformation($"{nameof(WeatherForecastController)}.{nameof(Get)} start");
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment