Click here to Skip to main content
14,838,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have developed website and i am able to publish it and was hosting it in remote IIS server,
but after adding global.asax file into my project i am not able to Publish it But when i build it and run the website its successfully running But when i try to publish website it rasising only an error saying Object reference is not set to an Instance of an Object not showing any line no or any info. Excluding the global.asax file it'll publish. Please help me out with this issue.
Below is my code and am using it for error log.

void Application_Start(object sender, EventArgs e)
   {
       // Code that runs on application startup
       if (!System.Diagnostics.EventLog.SourceExists("ERSite"))
       {
           System.Diagnostics.EventLog.CreateEventSource("ERSite", "ErrorLog");
       }
   }


   void Application_Error(object sender, EventArgs e)
   {
       // Code that runs when an unhandled error occurs
       Exception ex = Server.GetLastError();
       if (ex != null)
       {
           ErrorLog el = new ErrorLog();
           el.Log(ex);

           Server.ClearError();

           Response.Redirect("Error.aspx");
       }
   }


Is ErrorLog class where i have logging exception into windows eventlog .

Regards

Vivek
Posted
Updated 25-Feb-14 21:56pm
v5
Comments
CoderPanda 26-Feb-14 3:28am
   
Hi, Seems like your code isn't building. Can you mention what is the line in global.asax file is throwing that error?
Vivek Shankar 26-Feb-14 3:35am
   
It will build n it'll run successfully, when i try to publish it is showing the error, its showing any line no or any source.
JoCodes 26-Feb-14 3:35am
   
Debug and see where exactly its throwing error in Global.asax?Can you show the Code in Global.asax?
Vivek Shankar 26-Feb-14 3:42am
   
Yes done, Its not showing any error while debugging, Only while publishing it is showing error.
Below is my code and am using it for error log.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
if (!System.Diagnostics.EventLog.SourceExists("ERSite"))
{
System.Diagnostics.EventLog.CreateEventSource("ERSite", "ErrorLog");
}
}


void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = Server.GetLastError();
if (ex != null)
{
ErrorLog el = new ErrorLog();
el.Log(ex);

Server.ClearError();

Response.Redirect("Error.aspx");
}
}

1 solution

All files for which "Build action" is set to content will be deployed.
Highlight the global.asax file in the solution explorer and press ALT+ENTER to bring up the properties window for the file.
Check that build action is set to content.

[Please accept/up-vote answers or solutions that work for you to encourage participation]
   

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