WCF RIAServices 抛出异常的查询存在缓存问题
在 Silverlight 中使用 WCF RIA 服务时,我们遇到 HTTP 响应缓存问题。
服务器端,我们有一个简单的 DomainService GET 方法,没有指定缓存,如下所示:
[OutputCache(OutputCacheLocation.None)]
public IQueryable<SearchResults> GetSearchResults(string searchText);
当用户未经过身份验证时(即 FormsAuthenticationCookie 过期时),会抛出 DomainException。这是设计好的。
但是,当用户重新进行身份验证,并且使用相同的“searchText”参数再次调用查询时,查询永远不会到达服务器(没有断点命中;Fiddler 显示没有发送 http 请求)。
我认为这是因为当服务器上抛出异常时,HTTP响应将'Cache-Control'属性设置为'private',并且当客户端想要如果稍后(用户登录后)执行相同的查询,则浏览器甚至不会向服务器发送请求。
如果我们输入不同的搜索参数,那么重新执行查询就没有问题。
有没有办法确保http响应始终“无缓存” - 即使它没有正常返回?
UPDATE1 该问题仅在部署到 IIS 时出现 - 当使用 Casini 或 IIS Express 从 Visual Studio 进行测试时,它工作正常。
更新2 我更新了问题以反映新知识。
We have a problem with HTTP Response caching when using WCF RIA Services with Silverlight.
Server side, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该因授权错误而引发 DomainException。由于 Silverlight 处理故障的方式,这些响应仍然可以由您的浏览器缓存。相反,从 DomainService 抛出 UnauthorizedAccessException,这应该可以修复客户端上的缓存错误。
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.