I created an application with Silverlight4, RIA Services, and I use ASP.NET membership for authentication / authorization.
My web.config has the following:
<system.web> <sessionState timeout="20"/> <authentication mode="Forms"> <forms name="_ASPXAUTH" timeout="20"/> </authentication>
I read several different strategies on how to deal with client-side auth / session timeout. That is: if the client is idle for x minutes (20 here), and then they do something with the user interface that launches the RIA / WCF call, I want a trap on this event and deal with it accordingly (for example, return them back to the login screen) - in a nutshell: I need a way to distinguish from a bona fide DomainException server on the auth failure side because the session was disconnected.
AFAIK: There is no typed exception or property that can define this. The only way I could figure this out was like a hack: check the line with the error message and look for something like "Access denied" or "denied". For example: something like this:
if (ex.Message.Contains("denied")) // this is probably an auth failure b/c of a session timeout
So, this is what I am doing now and it works if I run and debug either with the built-in server from VS2010, or I run in the local IIS. If I set the timeout to 1 minute, log in, wait more than a minute and call another call, I will focus on the exception and enter the if code code above, and everything will be fine.
Then I deploy the application to the remote IIS7 server and I try the same test and it does not work. So, I added a log trace, and here an event occurred in which an exception occurred:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> <EventID>131076</EventID> <Type>3</Type> <SubType Name="Error">0</SubType> <Level>2</Level> <TimeCreated SystemTime="2011-10-30T22:13:54.6425781Z" /> <Source Name="System.ServiceModel" /> <Correlation ActivityID="{20c26991-372f-430f-913b-1b72a261863d}" /> <Execution ProcessName="w3wp" ProcessID="4316" ThreadID="24" /> <Channel /> <Computer>TESTPROD-HOST</Computer> </System> <ApplicationData> <TraceData> <DataItem> <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"> <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier> <Description>Handling an exception.</Description> <AppDomain>/LM/W3SVC/1/ROOT/sla-2-129644844652558594</AppDomain> <Exception> <ExceptionType>System.ServiceModel.FaultException`1[[System.ServiceModel.DomainServices.Hosting.DomainServiceFault, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> <Message></Message> <StackTrace> at System.ServiceModel.DomainServices.Hosting.QueryOperationBehavior`1.QueryOperationInvoker.InvokeCore(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.DomainServices.Hosting.DomainOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) </StackTrace> <ExceptionString>System.ServiceModel.FaultException`1[System.ServiceModel.DomainServices.Hosting.DomainServiceFault]: (Fault Detail is equal to System.ServiceModel.DomainServices.Hosting.DomainServiceFault).</ExceptionString> </Exception> </TraceRecord> </DataItem> </TraceData> </ApplicationData> </E2ETraceEvent>
The problem is that I don't have a line in the error message that says "denied" or "Access denied" - and I'm not sure why this solution works on the local IIS or VS2010 host, but not on the remote IIS7. Are there any obscure configuration settings that I am missing here? Is there a better way to do this overall?