When you get the exception "No owin.Environment element was found in context." from Request.GetOwinContext (), this usually means that detecting the OWIN startup class failed.
Make sure IIS runs the code in Startup.cs (in the root folder) at startup. To check if it works on a production server, I would recommend the following. 1) Insert the following line:
... System.Diagnostics.Trace.WriteLine("OwinStartup " + this.GetType().Namespace); ConfigureAuth(app); ...
2) Get the DebugView utility here: https://technet.microsoft.com/en-us/library/bb896647.aspx
3) Run DbgView.exe as an administrator and make sure that the option "Capture / Capture Global Win32" is enabled.
4) When starting IIS, you should see a trace message from the above code (make sure it really rebooted by clicking web.config).
5) If it is not executed check here: http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection
There are a number of reasons why it is not executed. Many of them are in stackoverflow. Another that I will add is the following: make sure that you do not have the parameter “batch = false” in the “compile” node of the website.
Harry kakoulidis
source share