Reputation: 7042
I was manually porting my application from ASP.NET MVC 5 to 6 (ASP.NET 5) and it uses the DNX and the .NET Core. I was using Request.UserHostAddress
and Request.UserAgent
in my controllers, but I couldn't add the System.Web
as a reference to the project.
How can I use Request and Response classes in ASP.NET 5 (MVC 6)?
Upvotes: 2
Views: 1489
Reputation: 17424
If your controller derive from Microsoft.AspNet.Mvc.Controller
you can access to HttpContext
, Request
and Response
properties.
this sample will help you to access to replacements of UserHostAddress
and UserAgent
public class HomeController : Controller
{
public IActionResult Index()
{
var address = HttpContext.Connection.RemoteIpAddress; // Request.UserHostAddress
var userAgent = Request.Headers["User-Agent"].FirstOrDefault(); // Request.UserAgent
return View();
}
}
Upvotes: 0