How can I access the HttpServerUtility instance in ASP.NET MVC controller?
Controllers are just classes you can call action like methods from another controller. The razor page you want to return must be from some controller action . Call that action using new Controller. Action(params) return result as result is IActionResult for mvc.
In Solution Explorer, right-click the Controllers folder and then click Add, then Controller. In the Add Scaffold dialog box, click MVC 5 Controller with views, using Entity Framework, and then click Add. Select Movie (MvcMovie. Models) for the Model class.
"this.httpContext.Server" is a reference to HttpServerUtilityBase, the abstract class wrapper that's a part of the System.Web.Abstractions DLL. You can also do:
HttpContext.Current.Server
To directly access the "old-school" way. Also you can get an instance of the base class using the wrapper by doing the following:
new HttpServerUtilityWrapper(HttpContext.Current.Server)
The wrapper class inherits from httpServerUtilityBase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With