Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the HttpServerUtility instance in ASP.NET MVC controller?

Tags:

asp.net-mvc

How can I access the HttpServerUtility instance in ASP.NET MVC controller?

like image 778
burnt1ce Avatar asked Nov 17 '10 16:11

burnt1ce


People also ask

How do you call a page with a 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.

How do I find controller model value?

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.


1 Answers

"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

like image 184
Brian Mains Avatar answered Sep 25 '22 09:09

Brian Mains