Problems with Application Cache as a result of interrupted browser requests to server

I have a legacy web application that I recently migrated from .NET 1.1 to .NET 2.0.
1. This application has a http handler defined and is configured as follows in the web.config:
      <add verb="*" path="*.aspx" type="AssetMgmt.SecurityHttpHandlerFactory, AssetMgmt" />
2. The application cache is setup with common tables of data during the Application_Start event.
3. During the Application_BeginRequest event, the cache is checked for validity, and if it is not valid or null, the cache is reloaded.
4. During the Application_AuthenticateRequest event, several security related datasets (including user accessible web-pages) associated with the current user are added to the context.
5. The http handler uses the accessible web-page dataset mentioned in 4 above to determine if the user has access to a given web page. If the user does not have access, the user is redirected to an Unauthorized page.

We have an intermittant problem which normally happens during the first access of this web application in the morning, where since the cache has expired overnight, it has to be reloaded. As a result, the response from the server is really slow. As a result of the slow response, the user will re-request the web application before the original request has completed. The user does this by either reselecting the web-site from Internet Explorer Favorites or hitting return on the address bar multiple times. The result is that during 4 above, during the loading of the security datasets, an exception with a message of "Constraint matches constraint named Constraint2 already in collection." is thrown and handled and then during 5 above, the web-site is not included in the accessible web-site dataset so the user is redirected to the unauthorized page.

I am trying to understand why this happens and how to fix the problem.
drpettittAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sasapopovicCommented:
Hi drpettitt,

It looks to me like an concurent resource access issue. I assume you use the same reference to DataSet (or some other classes) instance in those two attempts and it gets updated when it shouldn't.

I suggest you lock the access to that DataSet or access to cache. You can check this article for an example of how to perform locks: http://www.codeguru.com/csharp/.net/net_asp/article.php/c5363/

I hope this will help you.

Regards,
Sasa
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drpettittAuthor Commented:
sasapopovic,

Thanks for the help. Seems like I should have known this. Something about not seeing the forest for the trees comes to mind.

Thanks again,
Doug
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.