草庐IT

user_offtopic_count

全部标签

c# - SignalR OnDisconnected - 处理聊天室 "User is Online"的可靠方法?

我正在实现一个聊天室。到目前为止,一切都很好——用户可以通过JS客户端从他们的浏览器发送消息,我可以使用C#客户端来做同样的事情——这些消息被广播给其他用户。现在,我正在尝试实现“在线用户”。我的方法如下:OnConnected-将数据库中的用户更新为IsOnline=trueOnDisconnected-如果用户没有任何其他连接,则将数据库中的用户更新为IsOnline=false我将状态存储在数据库中,因为无论如何我都必须在数据库中查询用户缩略图-这似乎是在中心使用词典的一种简单替代方法。我遇到的问题是OnDisconnected并不总是为每个客户端ID调用-陈旧的连接阻止了“如果

c# - SQL 错误 : Incorrect syntax near the keyword 'User'

我正在使用SQL将数据插入到使用C#的SQL数据库文件中,如下所示。Stringcs=System.Configuration.ConfigurationManager.ConnectionStrings["connection1"].ConnectionString;SqlConnectionconn=newSqlConnection(cs);Stringsql="INSERTINTOUser(login,password,status)"+"VALUES(@login,@password,@status)";SqlCommandcomm=newSqlCommand(sql,conn

c# - HttpContext.Current.User.Identity.Name 如何知道存在哪些用户名?

这不一定是个问题,我只是好奇它是如何工作的。我有一个方法:publicstaticboolUserIsAuthenticated(){boolisAuthed=false;try{if(HttpContext.Current.User.Identity.Name!=null){if(HttpContext.Current.User.Identity.Name.Length!=0){FormsIdentityid=(FormsIdentity)HttpContext.Current.User.Identity;FormsAuthenticationTicketticket=id.Tick

c# - System.IO.Exception 错误 : "The requested operation cannot be performed on a file with a user-mapped section open."

我在写入XML文件时收到一个非常奇怪的IOException:System.IO.IOException:Therequestedoperationcannotbeperformedonafilewithauser-mappedsectionopen.atSystem.IO.__Error.WinIOError(Int32errorCode,StringmaybeFullPath)atSystem.IO.FileStream.Init(Stringpath,FileModemode,FileAccessaccess,Int32rights,BooleanuseRights,FileSh

c# - .NET 数组 - "Length"、 "Count()"和 "Rank"之间的区别

.NET数组的“Length”、“Count()”和“Rank”之间有什么区别? 最佳答案 Length是数组对象的属性,使用它是确定数组中元素数(Array.LengthinMSDNdocumentation)的最有效方法。Count()是一个LINQ有效相同的扩展方法。它适用于数组,因为数组是可枚举的对象。最好使用Length,因为Count()可能更昂贵(请参阅thisquestion进一步讨论和MSDNdocumentationonCount引用)。Rank是返回维数的属性(完全不同)。当你声明一个数组int[,]myArr

c# - 如何使用最小起订量模拟 Controller.User

我有几个ActionMethods可以像这样查询Controller.User的角色boolisAdmin=User.IsInRole("admin");在那个条件下方便地行动。我开始用这样的代码对这些方法进行测试[TestMethod]publicvoidHomeController_Index_Should_Return_Non_Null_ViewPage(){HomeControllercontroller=newHomePostController();ActionResultindex=controller.Index();Assert.IsNotNull(index);}并

c# - Linq Count() 比 List.Count 或 Array.Length 快还是慢?

是LINQCount()任何比List.Count更快或更慢的方法或Array.Length? 最佳答案 一般较慢。LINQ的计数一般是O(N)运行时List.Count和Array.Length都保证是O(1).然而,在某些情况下,LINQ会将IEnumerable作为特殊情况通过转换为某些接口(interface)类型的参数,例如IList或ICollection.然后它将使用该Count方法执行实际的Count()。手术。所以它会回到O(1).但是您仍然需要支付转换和接口(interface)调用的少量开销。

c# - 为什么 Count 不是无符号整数?

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicates:Whydoes.NETuseintinsteadofuintincertainclasses?WhyisArray.Lengthanint,andnotanuint我一直想知道为什么.Count不是无符号整数而是有符号整数?例如,以ListView.SelectedItems.Count为例。元素个数不能小于0,为什么是signedint?如果我尝试测试是否有元素被选中,我想测试if(ListView.SelectedItems.Count==0){}但是因为它是一个有符号整数,所以我必须测试if(List

c# - 使用 GROUP BY 和 COUNT(DISTINCT) 的 LINQ to SQL

我必须执行以下SQL查询:selectanswer_nbr,count(distinctuser_nbr)fromtpoll_answerwherepoll_nbr=16groupbyanswer_nbrLINQtoSQL查询fromaintpoll_answerwherea.poll_nbr=16selecta.answer_nbr,a.user_nbrdistinct映射到以下SQL查询:selectdistinctanswer_nbr,distinctuser_nbrfromtpoll_answerwherepoll_nbr=16到目前为止,还不错。但是,当尝试对结果进行GROU

c# - 为 WebClient 请求设置 User-Agent header

为WindowsPhone7的WebClient请求设置User-Agentheader的正确方法是什么?我找到了2个选项,但不确定哪一个是正确的。考虑WebClient对象:WebClientclient=newWebClient();我看到了2个选项:使用以下方法设置用户代理:client.Headers["User-Agent"]="myUserAgentString";使用WebHeaderCollection设置用户代理:WebHeaderCollectionheaders=newWebHeaderCollection();headers[HttpRequestHeader.