Skip to content

Instantly share code, notes, and snippets.

@eduardocp
Last active October 4, 2021 13:30
Show Gist options
  • Select an option

  • Save eduardocp/61daae2ee0af6a40bda3c4d4a6489a15 to your computer and use it in GitHub Desktop.

Select an option

Save eduardocp/61daae2ee0af6a40bda3c4d4a6489a15 to your computer and use it in GitHub Desktop.
HttpContext on .net core
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System.IO;
namespace System.Web
{
public static class HttpContext
{
private static IHttpContextAccessor _context;
private static IWebHostEnvironment _hostingEnvironment;
public static void Configure(IHttpContextAccessor httpContextAccessor, IWebHostEnvironment hostingEnvironment)
{
_context = httpContextAccessor;
_hostingEnvironment = hostingEnvironment;
}
public static Microsoft.AspNetCore.Http.HttpContext Current => _context?.HttpContext;
public static string MapPath(string path)
{
return Path.Combine(_hostingEnvironment.ContentRootPath, path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment