All events are executed 2 times.

zequion 446 Reputation points
2023-05-15T05:29:44.7533333+00:00

I have an Aspx project with the latest version of VS and .net 4.8.1 on Windows 11.

The problem is that in Global.asax the same events are being executed 2 times starting with Application_Start() Session_Start() index.aspx Session_End() Application_End() and starting a second time with Application_Start().

I have checked that there are no duplicate entries in Iis and I do not modify files like web.config or create files in the bin directory.

I have a second project that is a different web that calls the same dlls as the first. I have also made a copy of the first project to another 2 for testing. I've checked everything I can to get all projects to point to separate directories and everything seems to be fine.

Developer technologies | ASP.NET | Other
{count} votes

3 answers

Sort by: Most helpful
  1. zequion 446 Reputation points
    2023-05-16T03:37:29.14+00:00

    The problem is that application closes and starts again. Thanks to a function that I found on the internet to know the reason why the application closes, I have these messages but I still don't know the reason::

    "Change in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\c3af469b\fd9980fc\hash\hash.web\r\nHostingEnvironment initiated shutdown\r\nChange in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\c3af469b\fd9980fc\hash\hash.web\r\nHostingEnvironment caused the closure"

    " en System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)\r\n en System.Environment.get_StackTrace()\r\n en System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()\r\n en System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()\r\n en System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)\r\n en System.Web.Compilation.BuildManager.OnWebHashFileChange(Object sender, FileChangeEvent e)\r\n en System.Web.DirectoryMonitor.FireNotifications()\r\n en System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)\r\n en System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)\r\n en System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\r\n en System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\r\n en System.Threading.ThreadPoolWorkQueue.Dispatch()"


  2. zequion 446 Reputation points
    2023-05-16T04:59:52.2633333+00:00

    Sometimes the Application_Error() event is fired with this message:

    {"(0): error CS0006: Metadata file 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\c3af469b\fd9980fc\App_GlobalResources.dll' could not be found"}

    0 comments No comments

  3. zequion 446 Reputation points
    2023-05-17T01:15:38.39+00:00

    I just found something. I have seen that in a new project in web.config the line appears:

    <compilation debug="true" targetFramework="4.8.1" />

    In my projects I have the line:

    <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.8.1">

    In iis, server, ".net Build", "Optimize Builds" is = false.

    I have removed "optimizeCompilations="true" in 2 projects and it has worked fine.It has shown index.aspx and has stayed in Session_Start().In the last project I have not removed that text and again I get the error, because session_end occurs and application_end.

    At no time had it seemed to me that this was going to cause such a big problem. Asp.net doesn't have to close application for this reason.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.