草庐IT

current_iteration

全部标签

c# - HttpContext.Current.Cache 是线程安全的吗?

请检查下面的代码:objDDLTable=HttpContext.Current.Cache["TestSet"]asHashtable;if(objDDLTable==null){objDDLTable=newHashtable();arrDDLItems=GetDropDownList("testDropDown");objDDLTable.Add("testDropDown",arrDDLItems);HttpContext.Current.Cache["TestSet"]=objDDLTable;}elseif(objDDLTable!=null&&!objDDLTable.C

c# - 使用最小起订量模拟 HttpContext.Current.Server.MapPath?

我正在对我的家庭Controller进行单元测试。在我添加保存图像的新功能之前,此测试运行良好。导致问题的方法如下所示。publicstaticvoidSaveStarCarCAPImage(intcapID){byte[]capBinary=Motorpoint2011Data.RetrieveCapImageData(capID);if(capBinary!=null){MemoryStreamioStream=newMemoryStream();ioStream=newMemoryStream(capBinary);//savethememorystreamasanimage//

c# - LinqToSQL 错误 : Operation is not valid due to the current state of the object

在更新命令期间,我收到以下错误:Operationisnotvalidduetothecurrentstateoftheobject我试图从更新命令中删除一列并且它工作正常。此列是一个FK,与其他工作正常的FK相似。这是执行更新的代码:ti.NumeroTitolo=titolo.Numero;ti.RKTipoTitoloGenereTitolo=titolo.RkTipoTitoloGenereTitolo;ti.RKBanca=titolo.RkBanca;ti.DataScadenza=titolo.DataScadenza;ti.RKTipoEsito=titolo.RkTi

c# - 扩展 ASP.NET 身份角色 : IdentityRole is not part of the model for the current context

我正在尝试在我的MVC5应用程序中使用新的ASP.NETIdentity,特别是我正在尝试将ASP.NETIdentity集成到现有数据库中。我已经阅读了有关DBFirst和ASP.NETIdentity的SO问题/答案,并且遵循了所有建议我仍然无法向我的数据库添加角色,尽管我在添加用户时没有问题。这是我的代码:varcontext=newPayrollDBEntities();varroleManager=newRoleManager(newRoleStore(context));boolroleExists=roleManager.RoleExists(roleDto.Name);

c# - 了解 TaskScheduler.Current 的行为

这是一个简单的WinForms应用程序:usingSystem;usingSystem.Diagnostics;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privateasyncvoidbutton1_Click(objectsender,EventArgse){varts=Task

c# - 错误绑定(bind) Gridview : "The current TransactionScope is already complete"

我正在对从Gridview发送的事件进行级联删除。删除在事务中。这是简化的代码:protectedvoidbtnDeleteUser_Click(objectsender,EventArgse){DataContextdb;db=newDataContext();using(TransactionScopets=newTransactionScope()){try{//deletesomedatadb.SubmitChanges();ts.Complete();}catch(Exceptionex){//handleerror}finally{db.Dispose();BindGrid

c# - Iterating Over ConcurrentDictionary 只读时,ConcurrentDictionary 是否被锁定?

我在我的网络应用程序中创建了一个ConcurrrentDictionary作为应用程序对象。它在session之间共享。(基本上用作存储库。)有时,任何可用的session都会将新项目添加到字典中。仅允许管理员查看现在,我想允许管理员列出字典中的所有值,但管理员不会添加或删除项目,相反我只会提供一种方式让管理员查看通过遍历项目来读取集合中的项目。(伪)代码看起来像这样:foreach(vareinEmployeeCache.Instance.AllEmployees){Console.WriteLine(e.Key);}我的问题是:如果我遍历项目,ConcurrentDictionar

c# - HttpContext.Current.Session 为空

我有一个网站,在类库中有一个自定义缓存对象。所有项目都运行.NET3.5。我想将此类转换为使用session状态而不是缓存,以便在我的应用程序回收时在状态服务器中保留状态。但是,当我访问我的Global.asax文件中的方法时,此代码会引发“HttpContext.Current.Session为空”的异常。我这样称呼类:Customercustomer=CustomerCache.Instance.GetCustomer(authTicket.UserData);为什么对象总是空的?publicclassCustomerCache:System.Web.SessionState.IR

c# - 什么时候应该以 TaskScheduler.Current 作为参数调用 Task.ContinueWith?

我们正在使用thiscodesnippet从StackOverflow生成一个任务,该任务在任务集合中的第一个任务成功完成后立即完成。由于其执行的非线性特性,async/await并不是真正可行的,因此此代码改用ContinueWith()。不过,它没有指定TaskScheduler,它是numberofsources已经提到可能是危险的,因为它使用TaskScheduler.Current而大多数开发人员通常期望来自延续的TaskScheduler.Default行为。普遍的看法似乎是您应该始终将显式的TaskScheduler传递给ContinueWith。但是,我还没有看到关于何

c# - HttpContext.Current 如何在多线程环境中工作?

所以我想知道当(据我所知)asp.net是多线程时,asp.net究竟是如何能够限定静态属性的范围的。一种理论认为ASP.NET人员为每个请求维护一个不同的应用程序域......但这似乎不可行。另一种理论认为,.Current方法查看当前线程,然后使用它在某些哈希表(或其他静态存储机制)中查找http上下文。无论哪种方式,这都是一种看起来非常有用的技术......我想利用它,但绝对不想调试共享状态错误:-/ 最佳答案 它不是每个请求的AppDomain。如果你想使用线程特定的状态,尝试:[ThreadStatic]privatest