Search code examples
c#asp.net-mvcninjectnlog

MVC - Website crashes when browsing after sitting idle for 20 minutes, gives "The system cannot find the file specified error."


I have been wrecking my head regarding an error I keep getting in my ASP.NET MVC and EF 6 project. It is part of a large solution (18 projects) and only my project seems to be encountering an issue.

We use Ninject for Dependency Injection and all my settings match the other projects exactly. However, when viewing my site through HTTPS after sitting idle for 20 minutes when I go to navigate to another section within my application it spins, then crashes and shows an error

The system cannot find the file specified.

It goes on to also show a SqlException with error code 52. I can't find where this error is occurring. If I don't use HTTPS when viewing my site, it loads instantly and never has any problems.

I have error handling with logging added to all my controllers and yet this error is not logged. Instead, the only place I see this error is in Event Viewer and on the webpage.

It uses Forms Authentication, and has no session expiration time just like all the other sites. What I find weird is, if I refresh the home page (in another project) it fixes the issue. The home page utilizes a project that handles our authentication, role assignments, and so forth. It does utilize access to the same database. It uses database-first as its EF approach, as do the other projects.

Things I have done:

  • Converted my database-first context into a code-first with existing database
  • Changed the App Pool timeout to 100 (I doubt this was the problem since all other projects are fine and use the same App Pool)

Things different:

  • Only my project uses NLog, the other projects have a different logging utility

Would NLog be causing this issue? It is the only thing that seems to stick out, but I am not sure.

Is there any tools that can help my trace what kind of connection my site is trying to make when it gets that error?

Provided below is a bit of detail on the exception:

[Win32Exception (0x80004005): The system cannot find the file >specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]

Provided below is my Ninject configuration:

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(R.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(R.App_Start.NinjectWebCommon), "Stop")]
    namespace R.App_Start
   {
    using System;
    using System.Web;
    using Microsoft.Web.Infrastructure.DynamicModuleHelper;
    using Ninject;
    using Ninject.Web.Common;
    using Ninject.Web.Common.WebHost;
    using R.Service;
    using R.Interface;

    public static class NinjectWebCommon 
    {
        private static readonly Bootstrapper bootstrapper = new Bootstrapper();

        /// <summary>
        /// Starts the application
        /// </summary>
        public static void Start() 
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
            DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
            bootstrapper.Initialize(CreateKernel);
        }
        
        /// <summary>
        /// Stops the application.
        /// </summary>
        public static void Stop()
        {
            bootstrapper.ShutDown();
        }
        
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            try
            {
                kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                return kernel;
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }

        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<IZRepository>().To<ZRepository>();
            kernel.Bind<ICRepository>().To<CRepository>();
            kernel.Bind<IERepository>().To<ERepository>();
        }        
    }
}

Solution

  • The issue was the cookie timeout was set to exactly 20 minutes, changing the cookie timeout resolved the issue.