ASP.NET Session state lost after exception - asp.net

I've usually avoided in-proc session state, until this recent project. I think I have a problem where the state is lost after an unhandled exception occurs.
This in itself is odd, since exceptions in the context of a request don't down the worker process. It could be an exception on a background thread or a callback or something but, this is a simple site and there's nothing fancy going on.
The session ID remains the same and Session_Start is not called on the subsequent request (so the WP hasn't recycled).
I have quite a lot of logging enabled, and its plain to see that I get an exception from the data tier, its an HttpException inside a HttpUnhandleException, then when I browse immediately after to the home page, the request logs a warning about the missing state.
Worse. This doesn't happen on my dev box (IIS Express), only in QA.
Edit:
Here's a chunk of log:
2013-06-12 13:44:29,975 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET An unhandled exception occurred in the web application. The full exception will be unrolled below.
2013-06-12 13:44:30,897 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET Exception.Type: HttpUnhandledException
Exception.Source: System.Web
Exception.Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Exception.StackTrace: at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.HttpContext.InvokeCancellableCallback(WaitCallback callback, Object state)
at System.Web.UI.Page.LegacyAsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Exception.Type: HttpException
Exception.Source: CompanyNameProductName.MvcCoreApp
Exception.Message: An error was reported by the data layer: 0Image not found1-10.1007_978-1-4471-4294-2_21-16
Exception.StackTrace: at CompanyName.CompanyNameProductName.imagedetail.Page_Load(Object sender, EventArgs e) in c:\DATA\Git\ProductName\CompanyNameProductNameMvc\imagedetail.aspx.cs:line 55
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
2013-06-12 13:45:07,913 [25] DEBUG StandardPage 100.100.100.100 pxtgn GET Initializing page 'default_aspx' for GET with query string:
2013-06-12 13:45:07,913 [25] ERROR StandardPage 100.100.100.100 pxtgn GET No User instance in session state. Check the log for signs that the session was started properly since a User object should aways exist in session state, setup via session start events in ASP.NET.
The last line shows the missing state condition. The pxtgn is the first 5 chars from the session ID. I hit a page for which I know the data layer will barf about the non-existent image ID. Then any page I hit next will cause my check to log the problem with the missing state. The check and state reference is in the code for the master page, so I can hit any page to see the problem. This also means the custom error page doesn't work - which is sort of how I came to find the bug.
I've now added a Session.Abandon() after the check and respond with a 500 to get me out of jail, but its quite an odd problem. I'm new to the codebase, and I think I've checked everywhere for the session being cleared or state being overwritten.

1 Thread is destroyed
2 Asynchronous environment
use httpcontext as a Parameter
not system.web.**.httpcontext

Related

IIS appwhen adding a binding. servername.domain.com/app works, but appname.domain.com/app doesn't

I have a server whose sole purpose is to host a prebuilt IIS app from a vendor.
The server has been built, IIS is working, and with everything installed, the app is accessible from http://servername.domain.com/app
I want to add an alternate URL, to be http://appname.domain.com/app, for ease of use and cleanliness.
I added the binding on both ports 80 and 443 with our site cert, using all unassigned IPs and none of the boxes ticked.
Despite changing nothing but the bindings, I'm getting the following error attempting to use the newly bound URL:
Value cannot be null.
Parameter name: source
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: source]
System.Linq.Enumerable.Where(IEnumerable`1 source, Func`2 predicate) +6466184
Xtraction.Web.Auth.Authenticate.HasSingleActiveProvider() +185
Xtraction.Web.Auth.Authenticate.Page_Load(Object sender, EventArgs e) +115
System.Web.UI.Control.OnLoad(EventArgs e) +106
Xtraction.Web.PageBase.OnLoad(EventArgs e) +17
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3785
Based on the error information you provided, the reason I retrieved is that your application pool is not set up to use a service account, which prevents you from logging into Xtraction.
You need to set the application pool to use the Windows service account:
Go to IIS Manager > Servers > Application Pools > Xtraction
Click the Advanced Settings link in the right pane
Go to the Identity section, if it's set to Network Service, then click the ellipsis on the right
Change to "Custom Account" and enter your service account - this must have dbowner (or at least db_datareader and db_datawriter)
permissions on the Xtraction database
Click OK and restart the application pool (or execute iisreset). You should now be able to log in to Xtraction
For more information, you can refer to this link.

Session Variables Work in Chrome, Firefox but Fail in IE11

We recently upgraded a web server to Win2012 (from 2008) and started using ActiveDirectory. The main web site uses an external order form written in C# (ASP.NET 2.0). Everything was working fine in the old server until we migrated. Now I get errors when trying to read Session variables in IE 11 (everything works with other browsers).
This is the error I get with the line causing it:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 974: private void WriteTextConfirmation ()
Line 975: {
Line 976: string sFolders_OrderForm = Session ["Folders_OrderForm"].ToString ();
Line 977: string sOrderNumber = Session ["OrderNumber"].ToString ();
Line 978:
Source File: d:\Web Sites\Order Form\SubmitOrder.aspx.cs Line: 976
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
SubmitOrder.WriteTextConfirmation() in d:\Web Sites\Order Form\SubmitOrder.aspx.cs:976
SubmitOrder.Page_Load(Object sender, EventArgs e) in d:\Web Sites\Order Form\SubmitOrder.aspx.cs:1189
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +41
System.Web.UI.Control.OnLoad(EventArgs e) +131
System.Web.UI.Control.LoadRecursive() +65
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427
The problem is that the Session variables that are being read are null. They should be set in the Default form and passed for use in the SubmitOrder form. These variables work with FireFox and Chrome but fail in IE. I'm not sure why this would occur.
We had the same problem and setting the session state to cookieless in Web.config fixed our problem.
Since you are saying that it is browser-specific, it would have to be a setting with the browser. Maybe you have cookies turned off?
Update
I did some searching, and it looks like it could still be cookie related.
Session variable empty in iis7 application
Another common cause of this issue is when the server name contains
underscores (e.g. DEV_TEST). Underscores aren't allowed as host names,
and could interfere with the ability to set cookies.
This Server Fault question has a few answers saying the same thing:
https://serverfault.com/questions/178733/iis-7-0-does-not-keep-session-variables
And another SO question saying underscores:: IE8 does not keep Session Variables
More from Google: https://www.google.com/search?q=iis+application+session+variables+IE

Viewstate exception

In our website (ASP.NET Forms, Sitecore 6.6), in the log files I find so many viewstate exceptions. But there is no obvious issues reported by the users.
Here is the exception, by referring to the log files I found that this issue mainly occurs in a particular page which has a viewstate like 20KB. Please help to sort out this issue.
5676 00:30:43 ERROR Application error.
Exception: System.Web.HttpException
Message: The client disconnected.
Source: System.Web
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.HiddenFieldPageStatePersister.Load()
at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Nested Exception
Exception: System.Web.UI.ViewStateException
Message: Invalid viewstate.
Client IP: xxx.xxx.xxx.249
Port: 53377
Referer: <URL>
Path: /<PATH>
User-Agent: Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25
ViewState: cT4jo/ieR1NMvyqfwH6MToZmW6E/oKO64RcFXyllzcXB84wiWN/j3WeRyXxUZWCnr9c6staUp76B0Zr7/IqYgWWS3qfiMu9xzpU61bB+TAjDz0IbVwSt0rvZoFh7M/tQGQWyRha4ieCH7B5wKu3hXexRTIWwvP0JLbNmnQyFnOdqTnJZXBYQtaTyzMva3Fy7Q9YNstymtd1XrO1WHvUsBS6CwyV8eUYZs3LWRvczf3Ixz2XRg2Y4fY4kpuXl+QJLkbhgnALcFeGe9ur1l8Gyq6EdhqRb0BOlK4ozKaq4hpUT6HWes9YP2DjCJCpa2wP47hqZ5DaAXrcN+R6UPOqYIl6TSIjNUCv35NPPozaFjItLGmZi6ee+PfxOSz4ejxgBJzV3KNf2/1Mr5GNI7uZWgw998CI0mtxtpuWjp5kZCAfKzSCX//Vv7030VBLAE4Gj1RYIek1WNuwDreglFE5Pt8uKMDOsJstt8tXGqyCVcxqQAnRyN51e3uuqbDvDL2yVXA6yv6QyaCD/XmIHcgz//HItyqlhEziyOx7MxwKzpMyLu/6g2poqKMoNWtnQwxw9JTVwijEf45Lai+BOmgMNITgyrmLDp7ioHgHFK0VSmrSxN2W+CBRyyXWfn3QAy8UQYpq1TdHEUnGbc3XTTfBYW/gj+mFGaEpM24hUi/gJBxU2r+/wG2XxHfsxgrq6kG5cM8Hzf4GHuSC4...
Nested Exception
Exception: System.FormatException
Message: Invalid length for a Base-64 char array or string.
Source: mscorlib
at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
at System.Convert.FromBase64String(String s)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose)
at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose)
at System.Web.UI.HiddenFieldPageStatePersister.Load()
We have also seen this on our load balanced servers, specifically on pages where we use some form of ajax control (either ajax control toolkit, or home-grown).
The issue appears to be that the customer invokes some form of ajax request, then either closes their browser or goes to a different page either by a link or the browser back/forward controls.
One thing you can do, if you have control over when your response is sent to the client, is to do the following:
if(HttpContext.Current.Response.IsClientConnceted) {
//Send response
}
This should remove the error from your logs.
I've seen this same exception message in our logs for some time now and I have never been able to reproduce the issue until today, so I thought that I'd share my experience.
On a page using Ajax Update Panels, the user can first load the page. Then the user can invoke an Ajax request. If the user invokes another Ajax request, but hits the back button before the second Ajax request finished loading then the user is redirected to the previous page and the exception message is logged.
The user experience is not interrupted when this message is logged and therefore, the user doesn't know that anything happened behind the scenes. The exception message is accurate in terms of how view state is handled in the ASP.Net page life cycle.
I would say that the exception message is safe to ignore and you could likely find a solution to avoid having the exception message logged in the first place.
As a note, adding machine keys or addressing web server config settings has never helped me in any case regarding this exception message primarily because, in most cases, I was not using a web farm.

MSMQ: Message Queue service is not available. Error message

have had MSMQ working for the past few months but I am suddenly getting this error message:
Message Queue service is not available.
This is when i test it locally when I test it in live i get the follwoing message:
Unable to validate data.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to validate data.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Unable to validate data.]
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData) +4961431
System.Web.Security.MachineKey.Decode(String encodedData, MachineKeyProtection protectionOption) +194
System.Web.Helpers.AntiForgeryDataSerializer.Deserialize(String serializedToken) +120
[HttpAntiForgeryException (0x80004005): A required anti-forgery token was not supplied or was invalid.]
System.Web.Helpers.AntiForgeryDataSerializer.Deserialize(String serializedToken) +754
System.Web.Helpers.AntiForgeryWorker.Validate(HttpContextBase context, String salt) +199
System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) +156
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825488
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
Has anyone come across this problem where it has been working and then stops and any fixes for this?
Edit: I had a few issues setting up msmq see:
MSMQ creating errors: A workgroup installation computer does not support the operation / User's internal Message Queuing certificate does not exist
My set up we have 6 servers which are load balanced and all have msmq set up, the domain is set up as a Network service and there are two other server which are involved - the doamin controller which receives the messages and serach server which receives the message - i don t kow if there is a problem on all or just one particular server. I have tried to narrow it down by using the Host file (C:\Windows\System32\drivers\etc\Host )and pointing at each server at a time but they still seem to be sporadic in whther they work or not. We do use caching so I'm not sure if this may be affecting anything...
Thanks
I know this might sounds like a dummy solution, but it will worked with me for sure.
You need to remove MSMQ and install again, but in order for the other services to actually see it you need to restart in between every step ... so What you need to do as follow:
Remove MSMQ
Restart Server
Install MSMQ
Restart Server: Noting sometime this step is not needed it depends on whether the other services are able to see the MSMQ at this level or not.
Good luck
To resolve this problem, follow these steps:
Log on to your computer as an administrator.
Click Start, and then click
Run.
The Run dialog box appears.
In the Open box, type
Services.msc, and then click OK.
The Services window appears.
Locate Message Queuing. Right-click
Message Queuing, and then click
Properties.
The Message Queuing Properties (Local Computer) dialog box appears.
On the Log On tab, click Local System account.
Click Apply, and then click
OK.
Stop the Message Queuing service, and then start the Message Queuing service.

IIS7 giving Object reference not set to an instance of an object error

I have an IIS7 application that is using the .net 4.0 framework. The application pool has the rights (read/write/execute) on the folder of the application and has (select/read/connect) rights to the Database. IIS7 accept the aspx files and everything seems fine int eh settings however i am getting a 404 error when I am calling ti from outside of the server.
When I go in the server and call the http://localhost link, i get this error
Server Error in '/Phonebook/PhoneBook' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhanded exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
PhoneBookApplication.DBUtils.Execute(SqlCommand command) +399
PhoneBookApplication._Default.FillddlSearch() +156
PhoneBookApplication._Default.Page_Load(Object sender, EventArgs e) +54
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3047
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
If I call a default-defaut.html file, it works, but not if I call the default-defaut.aspx. But in the daufault pages settings, both aspx and html are there.
Also, it seems to have something to do with the sql server, but I do not understand where to look to debug that
I have no idea what is doing this. Can someone help?
The method DBUtils.Execute seems to have an error. What do do you have on the page_load or any event before the page_load ?
The error is telling you exactly where the problem is:
Your line 399 of the DBUtils class has a bug:
PhoneBookApplication.DBUtils.Execute(SqlCommand command) +399
IIS is not the problem. If you are getting a 404 error is because you are not going to the correct URL.

Resources