草庐IT

current_index

全部标签

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# - 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# - Elasticsearch 和 NEST : How do you purge all documents from an index?

我知道如何deleteanentireElasticSearchindex,但是如何从索引中清除所有文档?我的动机:我想要一个“ReIndex”方法来清除索引的全部内容,以便我可以重新加载所有文档。ElasticSearch语法会很有帮助。NEST语法会更好。 最佳答案 我在Nest中寻找类似的东西,我想我应该把语法放在这里供任何人寻找:varnode=newUri("http://localhost:9200");varsettings=newConnectionSettings(node);varclient=newElasti

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

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

c# - ASP.NET + C# HttpContext.Current.Session 为空(WebService 内部)

这是我发起session的方式protectedvoidSession_Start(objectsender,EventArgse){HttpContext.Current.Session["CustomSessionId"]=Guid.NewGuid();}在我的类库下的解决方案中,我正在尝试访问它并获得空异常:stringsess=HttpContext.Current.Session["CustomSessionId"];这是我在web.config和app.config中的配置(在我的库中)(应用程序配置) 最佳答案 根据您

c# - Parallel.Foreach 给出错误 "Index was outside the bounds of the array "

我在parallel.foreach中遇到了一些问题,即“索引超出了数组的范围”。我附上了parallel.foreach的一些代码以及崩溃的地方。varlstFRItems=session.CreateCriteria().Add(Restrictions.Eq("TSCEnterprise.FEnterpriseID",EnterpriseId)).AddOrder(Order.Asc("FName")).List();ListlstItemAccount=newList();varListAccounts=session.CreateCriteria().List();//lst

c# - 为什么 List<T> 出现 "Index was out of range"异常而不是数组?

当我初始化数组并使用索引器访问元素时,效果很好:object[]temp=newobject[5];temp[0]="bar";现在我希望同样适用于List,假设您可以通过将容量传递给构造函数来初始化它:Listtemp=newList(5);temp[0]="bar";然而,最后一行抛出以下异常:Indexwasoutofrange.Mustbenon-negativeandlessthanthesizeofthecollection为什么List会发生这种情况类型,但不是数组?由于数组只是CLR集合的较低级别抽象,那么为什么会出现此异常?原创question通过AwaisMahmo