473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to refer Request.ApplicationPath in Global.asax

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?


Nov 19 '05 #1
2 2546
BTW, why you want to do so?
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:u3**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 19 '05 #2
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>

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Daniel Rimmelzwaan | last post by:
I want to send a biztalk document to an aspx page, and I need to see some sample code, because I just can't make it work. I have a port with transport type HTTP, pointing to my aspx page, something...
8
by: GS | last post by:
What would be the sample code to stop processing any further requests in Application_onStart within global.asax has failed? Response.End does not work since there is no response object at the point...
5
by: Rory Becker | last post by:
I have had code in my Application_Start which is intended to run once at the start of my application's life. It loads connection information and similar from a known location. However I...
2
by: CKKwan | last post by:
Dear All, Using VS2008 on Vista (IIS7). Request.ApplicationPath return something like "http://localhost:50440/" When deploy into Server 2003 (IIS6), found that Request.ApplicationPath is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.