TBarCode .NET 常见问题
在 Web 场(IIS 7.0)中使用 TBarCode ASP.NET
在 Web 场(IIS 7.0)中使用 TBarCode ASP.NET
如果您在 Web 场中使用 TBarCode ASP.NET Web 控件,可能会遇到以下异常:
Exception Type: System.ApplicationException Message: The requested image is no longer cached.
TBarCode .NET Web 控件使用 HttpContext.Cache 对象来存储生成的条码图像。由于 http 请求在 Web 场内会进行负载均衡,因此可能出现某个特定 Web 控件收到的图像请求,实际上是在另一台应用服务器上生成的(因此在其本地缓存中并不存在)这种情况。
要解决此问题,您可以
- 在 Web 场中的所有服务器上同步 HttpContext.Cache 对象(即“分布式缓存”)。这可以通过额外的编程或第三方软件来实现。
- 或者,直接在 IIS 7.0 中使用客户端关联性 (Client Affinity)(推荐做法)
启用客户端关联性后,所有请求都会被打上 cookie 标记,从而使后续请求(来自同一客户端)被路由到 Web 场中的同一台服务器。
请参阅 Application Request Routing(步骤 3 — 配置客户端关联性)
Application Request Routing provides a client affinity feature that maps a client to a content server behind Application Request Routing for the duration of a client session. When this feature is enabled, the load balancing algorithm is applied only for the very first request from the client.![]()