Server Object - Where to find the Dll ?
-
Hello, I want to use the command Server.MapPath and need the Server object. Where I can found it for reference ?
The
Server
property is an intrinsic object accessible from within ASP.NET. You cannot simply useServer.MapPath
(which is actuallyHttpServerUtility.MapPath
) because 1) it's an instance method and you cannot instantiate theHttpServerUtility
class yourself, and 2) it only works with a given virtual path because it needs to map a virtual path to a physical path. This is specific to both the virtual host and the virtual directory. Even on two different virtual hosts, a virtual directory will map differently to the same physical directory. For future reference, if you have a question about what assembly a class (not object, which is an instance of a class) is defined in, you can view the bottom of the class documentation topic in the .NET Framework SDK that states what namespace and in what assembly the class (or any Type) is defined. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
The
Server
property is an intrinsic object accessible from within ASP.NET. You cannot simply useServer.MapPath
(which is actuallyHttpServerUtility.MapPath
) because 1) it's an instance method and you cannot instantiate theHttpServerUtility
class yourself, and 2) it only works with a given virtual path because it needs to map a virtual path to a physical path. This is specific to both the virtual host and the virtual directory. Even on two different virtual hosts, a virtual directory will map differently to the same physical directory. For future reference, if you have a question about what assembly a class (not object, which is an instance of a class) is defined in, you can view the bottom of the class documentation topic in the .NET Framework SDK that states what namespace and in what assembly the class (or any Type) is defined. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
Hello, thx for response. Yes I am working on an ASP.NET project and need the MapPath Method. But if I cannot instantiate it, i have no possibilities accessing it ?
Vector7 wrote: Yes I am working on an ASP.NET project and need the MapPath Method. But if I cannot instantiate it, i have no possibilities accessing it ? Did you read what Heath said? You cannot instantiate it. It is created by the framework for you. In your page class there is a property called Server[^] which exposes a pre-existing instance of the class which you can use.
Do you want to know more? WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
-
Vector7 wrote: Yes I am working on an ASP.NET project and need the MapPath Method. But if I cannot instantiate it, i have no possibilities accessing it ? Did you read what Heath said? You cannot instantiate it. It is created by the framework for you. In your page class there is a property called Server[^] which exposes a pre-existing instance of the class which you can use.
Do you want to know more? WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
I have read it, but still not the correct hint. This is what I've looked for : HttpContext.Current.Server.MapPath :) Because I didn't found the Server object, I thought I need an explicit IIS dll. But now I found this in the web by chance ( all other places show System.MapPath instead the right ASP.NET Version ).
-
I have read it, but still not the correct hint. This is what I've looked for : HttpContext.Current.Server.MapPath :) Because I didn't found the Server object, I thought I need an explicit IIS dll. But now I found this in the web by chance ( all other places show System.MapPath instead the right ASP.NET Version ).
You can also access the
Server
property from thePage
class (or rather the instance of thePage
for your code, if you're running within a .aspx for example). Excuse me for wondering why you're trying to access theServer
property when you posted in the ADO/ADO.NET forum. Next time please use the appropriate forum, i.e. the ASP.NET forum. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog] -
You can also access the
Server
property from thePage
class (or rather the instance of thePage
for your code, if you're running within a .aspx for example). Excuse me for wondering why you're trying to access theServer
property when you posted in the ADO/ADO.NET forum. Next time please use the appropriate forum, i.e. the ASP.NET forum. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]Excuse me for wondering why you're trying to access the Server property when you posted in the ADO/ADO.NET forum. Next time please use the appropriate forum, i.e. the ASP.NET forum. Because I am developing a DB Application, where I need this in the connectionstring.
-
Excuse me for wondering why you're trying to access the Server property when you posted in the ADO/ADO.NET forum. Next time please use the appropriate forum, i.e. the ASP.NET forum. Because I am developing a DB Application, where I need this in the connectionstring.
It's still a question about ASP.NET. If you had a question about how to do a particular operation in C# you'd ask in the C# forum. The context of the application isn't as important as the context of the question. We don't know what you're writing, but if you ask in the right forum you'll get a more appropriate response. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]