How to refer Request.ApplicationPath in Global.asax

A

ad

I want to get the Application path, I use the code:
string sDir = Request.ApplicationPath ;

It run well in code behind, but if I place the code above in Global.asax
like:

void Application_Start(Object sender, EventArgs e) {

string sDir = Request.ApplicationPath ;
}

it will fail in run time.

How can I do that?
 
W

www.VoiceInformation.com

I'm using Server.MapPath and it's working for me -

<snippet>

// Logging and Configuration constants
private const string EVT_PROGRAMNAME = "TekGuard
WebMail";
private const string DIR_PATHPUBLIC =
"TGWebMail\\Pub\\";

// Internal Constants
internal const string APP_PATHPUBLIC = "PathPublic";
internal const string SES_USERNAME = "UserName";
internal const string SES_PATHUSER = "PathUser";


protected void Application_Start(Object sender, EventArgs e)
{
// Create the application level data path object
string PathServer = Server.MapPath("~/");

// Get the full path of the public directory
// m_PublicPath = PathServer + DIR_PATHPUBLIC; // Root of
virtual web
m_PublicPath = Directory.GetDirectoryRoot(PathServer) +
DIR_PATHPUBLIC;

// Do I have directory storage permission, etc?
try
{
if (!Directory.Exists(m_PublicPath))
Directory.CreateDirectory(m_PublicPath);

// Create the application level data path object; Store the
path for page use
Application.Add(APP_PATHPUBLIC, PathPublic);
}
catch(Exception ex)
{
// m_LogTools.WriteWinAppEvent ("Error setting bootstrap
initialization settings (see log file for details), " + ex.Message,
EventLogEntryType.Error);
Response.Write (EVT_PROGRAMNAME + ": " + ex.Message);
throw new ApplicationException(EVT_PROGRAMNAME + ": " +
ex.Message);
}
}



internal static bool
UserInit(System.Web.SessionState.HttpSessionState Session, object
UserName, object ServerName)
{
// Create the fully qualified directory path for this user
string PathUser = m_PublicPath + ServerName.ToString().ToLower()
+ "\\" + UserName.ToString().ToLower() + "\\";

// Do I have directory storage permission, etc?
try
{
if (!Directory.Exists(PathUser))
Directory.CreateDirectory(PathUser);
Session.Add(SES_PATHUSER, PathUser);
return (true);
}
catch
{
}
return (false);
}

private void Page_Load(object sender, System.EventArgs e)
{
// Load default identity data from XML
path = Session[Global.SES_PATHUSER].ToString()
...
...
...
}

</snippet>



www.VoiceInfo.com - <a href="http://www.VoiceInfo.com">
Virtual Office, Automated Phone Assistant, Web Access </a><br>

www.TekGuard.com - <a href="http://www.TekGuard.com">
Free Mail Server, Outlook PlugIn, WebMail, Source Code </a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top