Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an webapplication.

In a class file i have written this code
C#
string logFile = "App_Data/ErrorLog.txt";
logFile = HttpContext.Current.Server.MapPath(logFile);

And in global.asax page I have written on event of application_error.
C#
Exception exc = Server.GetLastError();
if (exc.GetType() == typeof(HttpException))
            {
                // The Complete Error Handling Example generates
                // some errors using URLs with "NoCatch" in them;
                // ignore these here to simulate what would happen
                // if a global.asax handler were not implemented.
                if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
                    return;

                //Redirect HTTP errors to HttpError page
                Server.Transfer("HttpErrorPage.aspx");
            }


At the position of Exception exc = Server.GetLastError(); it gives error.

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (C:\Documents and Settings\Pankaj_singh\My Documents\Visual Studio 2008\Projects\SPH11\images\web.config line 75)
at System.Configuration.ConfigurationSchemaErrors.



But my virtual directory path upto C:\Documents and Settings\Pankaj_singh\My Documents\Visual Studio 2008\Projects\SPH11
then also it shows upto C:\Documents and Settings\Pankaj_singh\My Documents\Visual Studio 2008\Projects\SPH11\images
path.

Please give me solution for that.

Thanks in advance
Posted
Updated 28-Oct-11 21:29pm
v3

1 solution

Please try following to access app_data folder,

C#
string appdatafolder = System.IO.Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "App_Data");
string logFile = appdatafolder + "\\ErrorLog.txt";


Hope this will help you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900