getting location of the server outside the website project

liptonIcedTea

Well-known member
Joined
Jan 18, 2007
Messages
89
Programming Experience
1-3
Hi, is it possible to get the location of the server outside of the website project?

I usually use Server.MapPath to find the server page but that method only seems accessible in the code behind page for each web form.

I do not seem to have access to the Page object in any web controls that I have outside of the main web form.
 
I do not seem to have access to the Page object in any web controls that I have outside of the main web form.
This makes perfect sense since a web form is based on (Inherits) the System.Web.UI.Page class and the various flavours of web controls do not. :)
The System.Web.UI.UserControl class also has a Server property, so calling Server.Mathpath will work in a UserControl.
The System.Web.UI.Control class doesn't have a Server property, but it does have a Context property which in turn has a Server property. So in a System.Web.UI.Control based control, you can call Context.Server.Mathpath.
 
the control is part of the solution, but not in the website project. it's in the data access layer.

I had to access the file system on the server. i ended up just referencing the server url in my app config and then accessing it from there.
 
When you compile the control, reference it in the website project and add it to a web form, it will run in the same context as the page. Thus you can use the control's Context property to reference the Server.
 
Back
Top