我的产品服务器上的 MVC3 应用程序有问题(我在 VS12 中没有任何问题)。
- jQuery 1.8.2
 - 自动常见问题
 - 存储库模式
 - log4net
 - 自动映射器
 
该应用程序在 _Layout.cshtml 中有一些列表,必须通过 jQuery 每 5 秒更新一次。
代码看起来或多或少是这样的:
<script type="text/javascript">
    var products = $("#products ul");
    function updateProducts() {
        setTimeout(function() {
            $.post("/Product/List", { rows: 10 }, function(html) {
                products.before(html).remove();
                products = $("#products ul");
                // To avoid multiple posts update the list until the post is done
                updateProducts();
            });
        }, 5000);
</script>
控制器看起来像这样:
public PartialViewResult List(int rows)
{
    var products = productService.GetNewest(rows);
    return PartialView(products);
}
该服务如下所示:
public class ProductService : Service<Product>, IProductService
{
    private IRepository<Product> repository;
    public ProductService(IUnitOfWorkFactory unitOfWorkFactory)
    {
        IUnitOfWork unitOfWork = unitOfWorkFactory.Create();
        this.repository = unitOfWork.ProductRepository();
        base.Repository = this.repository;
        base.UnitOfWork = unitOfWork;
    }
}
public List<Product> GetNewest(int rows)
{
    var products = repository.GetAllQueryable(); //=> returns a IQueryable
    products.OrderBy(o => o.CreateDate).Take(rows);
    return products.ToList();
}
存储库(EF 5.0 代码优先):
public class Repository<T> : IRepository<T> where T : Base
{
    private RepositoryContext _dataContext;
    private IDbSet<T> _dbset;
    public virtual IQueryable<T> GetAllQueryable()
    {
        var all = _dbset;
        return all;
    }
}
工作单位:
public class UnitOfWork : Disposable, IUnitOfWork
{
    private RepositoryContext _dataContext;
    private Repository<Product> _productRepository;
    public IUnitOfWork GetCurrent()
    {
        _dataContext = _dataContext ?? (_dataContext = new RepositoryContext());
        return this;
    }
    public IRepository<Product> ProductRepository()
    {
        _productRepository = _productRepository ?? new Repository<Product>(_dataContext);
        return _productRepository;
    }
}
部分视图仅包含一个返回产品名称的 foreach。
即使我只有一个需要更新的列表,页面加载速度也会变慢并且是随机的。我还使用 log4net 来检查当 jQuery 尝试获取产品时是否发生了某些事情,但日志是空的 :)。
我还调查了 MiniProfiler 的问题。最慢的(最多 15 秒)是 ASP.NET 开始请求。
产品服务器:
- 视窗 2008
 - 3GB 内存
 - 2 个其他 .NET 应用程序
 - SQL08
 
编辑
看来问题已经解决了,耶!感谢@vtortola 对会话的提示。我做了一些研究,发现了很好的链接。然后我创建了一个新的控制器,上面有 [SessionState(SessionStateBehavior.ReadOnly)]。就是这样,一个属性解决了我的问题:)!
这是一个有用的链接,尤其是当您想要像 ReadAndWrite 这样的 SessionStateBehavior http://www.davidcoombes.co/?p=151