草庐IT

user_role

全部标签

c# - 无效操作异常 : Cannot create a DbSet for 'Role' because this type is not included in the model for the context

以下解决方案适用于.netcore1.1,但从1.1升级到2.0后,我收到以下错误:InvalidOperationException:CannotcreateaDbSetfor'Role'becausethistypeisnotincludedinthemodelforthecontext.当用户尝试登录并执行以下语句时:varresult=await_signInManager.PasswordSignInAsync(model.Email,model.Password,model.RememberMe,lockoutOnFailure:false);怎么了?User.cspubl

c# - 登录成功后User.Identity.IsAuthenticated为false

登录成功后需要直接获取UserIdGuid。以下代码不起作用:if(Membership.ValidateUser(txtUsername.Value,txtPassword.Value)){FormsAuthentication.SignOut();FormsAuthentication.SetAuthCookie(txtUsername.Value,true);if(HttpContext.Current.User.Identity.IsAuthenticated){//doesn'trunGuidpuk=(Guid)Membership.GetUser().ProviderUse

c# - 如何在 Asp.Net MVC 4 中模拟 HttpContext.User.Identity.Name

我在Controller中有使用HttpContext的代码publicActionResultIndex(){varcurrentUser=HttpContext.User.Identity.Name;......}当尝试像这样使用NUnit编写测试时[Test]publicvoidCanDisplayRequest(){//Actvarresult=(ViewResult)_requestController.Index();//AssertAssert.IsInstanceOf(resut.Model);}测试将失败,因为它找不到HttpContext那么我如何模拟HttpCon

c# - 具有 HttpContext.Current.User.Identity.IsAuthenticated 的 Webmethods 在 Azure 上不活动后停止工作

我正在使用使用Ajax(json)/Webmethod函数的页面测试Azure服务器。其中一些函数在运行代码之前会检查HttpContext.Current.User.Identity.IsAuthenticated。不幸的是,如果用户已登录并且页面没有向服务器发出完整的回发请求,则只有那些检查HttpContext.Current.User.Identity.IsAuthenticated的webmethods函数会在一对夫妇之后完全停止运行分钟没有给出任何错误。他们甚至不运行else代码块(见下文)。我已经在本地服务器上测试了这些页面,一切正常,即使在长时间不活动之后也是如此。这是

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

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

c# - 如何修复 : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical?

我正在对SQLServer2012数据库使用EntityFramework4.3.1,并且我正在使用POCO方法。我收到以下错误,我想知道是否有人可以解释如何修复它:模型验证异常Oneormorevalidationerrorsweredetectedduringmodelgeneration:\tSystem.Data.Entity.Edm.EdmAssociationConstraint::ThenumberofpropertiesintheDependentandPrincipalRolesinarelationshipconstraintmustbeidentical.没有可用

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# - 如何使用最小起订量模拟 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);}并