开发者

WCF RIAServices Querys that throw exceptions have caching problems

We have a problem with HTTP Response caching when using WCF RIA Services with Silverlight.

Server side开发者_StackOverflow社区, we have a simple DomainService GET method with no caching specified, like this:

  [OutputCache(OutputCacheLocation.None)]
  public IQueryable<SearchResults> GetSearchResults(string searchText);

The throws a DomainException when the user is not authenticated (i.e. when the FormsAuthenticationCookie expires). This is as designed.

But when the user is re-authenticated, and the Query is called again with the same 'searchText' parameter, then the Query never gets to the server (no breakpoint hit; Fiddler shows no http request sent).

I think this is because when the exception is thrown on the server, the HTTP Response has the 'Cache-Control' property set to 'private', and when the client wants to perform the same query later (once the user is logged in), then the browser does not even send the request to the server.

If we enter a different search parameter, then the query is re-executed no problem.

Is there any way of ensuring the http response always has 'no-caching' - even when it does not return normally?

UPDATE1 The problem only occurs when deployed to IIS - when testing from Visual Studio with either Casini or IIS Express it works fine.

UPDATE2 I updated the question to reflect new knowledge.


You shouldn't be throwing a DomainException for authorization errors. Due to the way Silverlight handles faults, these responses can still be cached by your browser. Instead, throw an UnauthorizedAccessException from your DomainService and that should fix the caching error on the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜