I am getting a 'session state not available in this context' error.
The error is nested in the sender parameter of a number of methods within the Global.asax file:
Application_BeginRequest
Application_AuthenticateRequest
Session_Start
Application_Error
The error happens on the very first page load (and all page loads thereafter).
I've added a completely new and empty page, WebForm1.aspx, to the project and made it my start page.
You'd think nothing could go wrong on an empty page. No code of mine is executed, as far as I can see, when loading an empty page. But I'm still getting the session state error.
My project works totally fine. No error pages are shown. There is no incorrect behavior at any time.
But the fact that this session error shows up in the sender parameter of my current project bugs me. This error is not generated in a blank, new project.
What can possibly be the cause of this error in my current project?
How can I trace where the error occurs? I can't set breakpoints in ASP.NET code that's under the hood. Or can I?
Here's my session configuration:
<pages enableSessionState="true" />
<sessionState mode="InProc" cookieless="false" timeout="20" />
Update:
I just found out that a brand new blank project also has this error in the sender object. It's visible in the Application_BeginRequest and Application_AuthenticateRequest methods. But the blank project isn't generating the Application_Error event, like my other project is.
You are requesting for session state too early in the cycle. you need to do it in Application_AcquireRequestState
"If a tree falls in a forest and no one is around to hear it, does it make a sound?"
Don't watch the Session property at the point where it is not available yet.
Related
I am using below configuration in project.
javax.faces.PROJECT_STAGE Development javax.faces.STATE_SAVING_METHOD client but sometime it gives view could not be restored in ajax's partial response.
for example:
<partial-response id="j_id1">
<error>
<error-name>
class javax.faces.application.ViewExpiredException
</error-name>
<error-message>
<![CDATA[viewId:/workbench.xhtml - View /workbench.xhtml could not be restored.]]>
</error-message>
</error>
</partial-response>
Sometime no command button is working and there is no nested form. it was working fine almost 2 year now irregular of time it is giving this error after checking with firebug on client's system. sometime it gives 302,304 status for resources. It is very big project and single web application for the country and lots of concurrent user working.
Please help we are unable to solve the issue because it is not coming on when we do debugging on our end.
We have a JSF webapp with Primefaces 4.0 and CAS Single Sign On.
When a user requests an ajax action (by clicking a p:commandButton or similar component with ajax=true) after he has lost his session because SSOut in another tab, nothing happens, no response from server or action is triggered.
We need to manage that situation to inform the user that his session is no longer available, by showing a dialog or redirecting him to home or a custom page, but we don't know how.
ajax=false solves the problem, but this is not what we want to do.
No ViewExpiredException is thrown.
EDIT:
We had already read and tried this BalusC's solution without success. No Exception is thrown and Handler has nothing to do. Note that isn't an Expired Session or Invalidated by TimeOut session, is just an explicit session.invalidate caused by Cas Sign Out in another tab.
We also tried javascript jsf.ajax.addOnError() solution, and again nothing to capture.
Only p:ajaxStatus onError event catches something, but no way to identify that particular error. Even overriding ajaxStatus javascript function, error data parameter is undefined...
Also, p:log says "Request return with error:error." but, which error is it? how do we identify it?
We are stuck on this issue...
This has been discussed many times, and as far as know there aren't any out-of-the-box solutions yet. One solution is to add a custom ExceptionHandler as stated in this post.
Another option is to register client error handler using jsf.ajax.addOnError(...), and to handle this exception in it. You might need some server code to add a custom header in case session is invalid, which you would use in error handler to be able to differentiate that specific case from other errors.
I got few doubts on sessions in JSF and/or in general.
First up, does session gets created on load of an web app in AS/servlet container? Meaning, after I do right click- run as - run on server and the app is started and synchornised?
Or does it get created after the web app is loaded and the defined welcome page is displayed and then the client makes a request?
Second: I was looking into the issue of "Cannot create a session after the response has been committed" in jsf.
I was trying to reproduce the issue by doing this given in the following site,
http://java.net/jira/browse/JAVASERVERFACES-2215
But, I didnt get any error as mentioned above. I tried with all bean scope.
Was the session created?
This is the code.
<h:body>
<h:form id="test">
<p:growl id="msg"></p:growl>
<h:outputText value="#{myTestBean.exceedBuffer}" />
</h:form>
</h:body>
bean code is.
public String getExceedBuffer() {
int size = FacesContext.getCurrentInstance().getExternalContext().getResponseBufferSize();
char[] chars = new char[size];
Arrays.fill(chars, 'x');
return new String(chars);
}
My understanding is the following,
First when the app is loaded the servlet container or an AS creates a session and a sessionID(JSESSIONID) and puts it in server memory. So the initial page gets loaded up anyhow, meaning even if the response buffer is overflowed or not but the session wont be created. Now, when the client makes a request on this page, since the session was not created, the error occurs. But, I tried even doing this by
<p:commandButton actionListener="#{myTestBean.onSelect}" update=":test"></p:commandButton>
and in onSelect method just entered a dummy code. Even now the page displayed as usual.
Well, that was when I was completely lost. Can someone pls help me on this? Thanks in advance.
First up, does session gets created on load of an web app in AS/servlet container? Meaning, after I do right click- run as - run on server and the app is started and synchornised?
Or does it get created after the web app is loaded and the defined welcome page is displayed and then the client makes a request?
It's created on start of the HTTP session, not on webapp's startup (that's the application scope). Basically, when request.getSession() is called for the first time and the HttpSession hasn't been created yet. This all is handled by the Servlet API which JSF is using under the covers. So the following answer should help in understanding how it works: How do servlets work? Instantiation, sessions, shared variables and multithreading
Second: I was looking into the issue of "Cannot create a session after the response has been committed" in jsf.
I was trying to reproduce the issue by doing this given in the following site, http://java.net/jira/browse/JAVASERVERFACES-2215
But, I didnt get any error as mentioned above. I tried with all bean scope. Was the session created?
You will get this error when the HttpSession isn't created yet at the moment the response is committed. That you didn't get this error can only mean that the session has already been created beforehand. You need to test it on a freshly started webapp and the session shouldn't be created yet. Note that some servers by default stores sessions on shutown/restart. You'd need to disable this or to remove the JSESSIONID cookie in your browser before sending the first request on this test page. Restarting the webbrowser or using a different one should also force a fresh new session.
Anyone know how to turn off the default error page or where it's referenced??
Alright, I figured it out.
Turns out that in my custom ElmahHandleErrorAttribute class, the OnException() method is indeed over ridden (as it should be). But the 1st line of code is "MyBase.OnException(context)", which will fire off what the HandleError attribute also performs.
Once I commented out that one line, my issue went away.
What's The Issue?
I have Elmah.Mvc implemented in this Mvc4 project, it's working beautifully. I also have a custom errors section in the Web.config as follows:
<customErrors mode="On" defaultRedirect="~/Error/General">
<error statusCode="404" redirect="~/Error/Http404" />
</customErrors>
I have an ErrorController with two action methods, one for "General" and the other for "Http404".
What was happening was if I raised an unhandled error, I would indeed get my raised exception logged in Elmah, an email delivered with the exception, and then the custom "General" view displayed (Http404 page if it was a 404 error).
BUT, what I was also getting was an additional logged exception AND email because the default "Error.vbhtml" file was not found (I removed that view).
Honest mistake...hope this helps someone out moving along. :)
You can control this using the customErrors element in the web.config file.
I'm trying to set up an MVC application that will service several facebook applications for various clients. With help from Prabir's blog post I was able to set this up with v5.2.1 and it is working well, with one exception.
At first, I had only set up two "clients", one called DemoStore and the first client, ClientA. The application determines what client content and facebook settings to use based on the url. example canvasUrl: http://my_domain.com/client_name/
This works for ClientA, but for some reason when I try any DemoStore routes I get a 500 error. The error page points to an issue with the web.config.
Config Error:
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'facebookredirect.axd'
I am able to add additional clients with no problem, and changing DemoStore to something like "demo" while using the same facebook application settings works fine also.
Working calls:
http:// localhost:2888/ClientA/
http:// localhost:2888/ClientB/
http:// localhost:2888/Demo/
Failing call:
http:// localhost:2888/DemoStore/
I was thinking this might be an MVC issue, but the Config Error points to the facebookredirect handler. Why would the SDK try to add this value to the config during runtime, and only for this specific client?
Any insight would be greatly appreciated.
I managed to figure out what went wrong here. Silly mistake..
After I had set up the application routes to require the client_name I changed the Project Url in the project properties to point to demostore by default. When I hit ctrl+S a dialog popped up that I promptly entered through without reading.
When I changed the Project Url, IIS Express created a new virtual directory for the project. This was the source of my problem. Why? I'm not sure, but once I removed the second site from my applicationhost.config I was able to access the DemoStore routes.
Moral of the story: read the VS dialog messages!