0

I have an application that I built a few years ago running in ASP.NET 4.0. It was running fine, however the server crashed and we had to move the code to a new server. It was running in IIS 7 before, but now the new server ( 2016 ) is running IIS v 10. I've set up the application to the best of my memory as it was on the old server, and the app comes up. However, during the logon process I use the HttpContext.current and just this reference throws this exception:

Object reference not set to an instance of an object.

Since this has been running for years I fear there's just something I'm missing in setting the site up that basically has it with no HttpContext ( again, just trying to reference HttpContext.current crashes.

If anyone can point me in the right direction I would be greatly appreciative.

R15
  • 13,982
  • 14
  • 97
  • 173
  • It would be awesome if you could provide a [mcve] – jazb Nov 01 '18 at 07:05
  • In general you should only call `HttpContext.Current` in only a few scenarios (within an HTTP module for example). In all other cases, you should use `Page.Context` https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.context?view=netframework-4.7.2 or `Controller.HttpContext` https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.httpcontext?view=aspnet-mvc-5.2 – Lex Li Nov 01 '18 at 13:24

1 Answers1

0

Try Adding runAllManagedModulesForAllRequests="True" in the system.webServer/modules section in web.config as below

<modules runAllManagedModulesForAllRequests="True">

This may be due to ASP.NET Sessions error

PrathapG
  • 751
  • 1
  • 7
  • 21