草庐IT

ident_current

全部标签

c# - 路由请求时 HttpContext.Current.Session 为 null

没有路由,HttpContext.Current.Session有没有,所以我知道StateServer正在工作中。当我发送请求时,HttpContext.Current.Session是null在路由页面中。我在IIS7.0上使用.NET3.5sp1,没有MVC预览。看来AcquireRequestState使用路由时永远不会触发,因此不会实例化/填充session变量。当我尝试访问Session变量时,出现此错误:base{System.Runtime.InteropServices.ExternalException}={"Sessionstatecanonlybeusedwhe

c# - 尝试激活 'Microsoft.AspNetCore.Identity.UserManager` 时无法解析类型 'AuthController' 的服务

我在登录Controller中收到此错误。InvalidOperationException:Unabletoresolveservicefortype'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]'whileattemptingtoactivate'Automobile.Server.Controllers.AuthController'.这是AuthController的构造函数:privateSignInManager_signManager;privateUserManager_us

c# - 从不同线程访问 HttpContext.Current

我有一个C#ASP.NET应用程序,它启动了大约25个不同的线程,在一个名为SiteCrawler.cs的类中运行一些方法。在HttpContext.Current.Session中,我想保存用户搜索的结果,并在所有线程运行完毕后将其呈现给用户。我的问题是HttpContext.Current对象在生成的线程中为空,因为它在那里不存在。由于应用程序是多线程时的限制,我还有哪些其他选项可以在不使用session的情况下保存用户/session特定数据?我试图搜索Stackoverflow的每一寸空间以找到解决方案,但没有任何运气.... 最佳答案

c# - ASP.NET Core Identity - 获取当前用户

要在MVC5中获取当前登录的用户,我们所要做的就是:usingMicrosoft.AspNet.Identity;[Authorize]publicIHttpActionResultDoSomething(){stringcurrentUserId=User.Identity.GetUserId();}现在,对于ASP.NETCore,我认为这应该可行,但它会引发错误。usingMicrosoft.AspNetCore.Identity;usingMicrosoft.AspNetCore.Http;privatereadonlyUserManager_userManager;[Http

c# - 在 ASP.NET Identity 2.0 中获取当前用户 ID

我刚刚转而使用新的2.0版身份框架。在1.0中,我可以使用manager.FindByIdAsync(User.Identity.GetUserId())获取用户对象。GetUserId()方法似乎在2.0中不存在。现在我能想到的就是使用manager.FindByEmailAsync(User.Identity.Name)来引用用户表中的用户名字段。在我的应用程序中,这设置为与电子邮件字段相同。当有人需要更新他们的电子邮件时,我可以看到这会导致问题。有没有一种方法可以根据身份2.0框架中不变的值(例如id字段)获取当前登录的用户对象? 最佳答案

c# - 如何更新 ASP.NET Identity 中的声明?

我正在为我的MVC5项目使用OWIN身份验证。这是我的SignInAsyncprivateasyncTaskSignInAsync(ApplicationUseruser,boolisPersistent){varAccountNo="101";AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);varidentity=awaitUserManager.CreateIdentityAsync(user,DefaultAuthenticationTypes.ApplicationCookie);

c# - 为什么等待后 HttpContext.Current 为空?

我有以下测试WebAPI代码,我没有在生产中使用WebAPI,但我之所以这样做是因为我对这个问题进行了讨论:WebAPIAsyncquestion无论如何,这是有问题的WebAPI方法:publicasyncTaskGet(intid){varx=HttpContext.Current;if(x==null){//notthrownthrownewArgumentException("HttpContext.Currentisnull");}awaitTask.Run(()=>{Task.Delay(500);id=3;});x=HttpContext.Current;if(x==nu

c# - 在 Asp.net Identity MVC 5 中创建角色

关于使用新的Asp.net身份安全框架的文档非常少。我已经拼凑了我可以尝试创建一个新角色并向其添加一个用户的方法。我尝试了以下操作:AddroleinASP.NETIdentity看起来它可能从这个博客中获得了信息:buildingasimpleto-doapplicationwithasp.netidentityandassociatinguserswithto-does我已将代码添加到数据库初始化器中,该数据库初始化器在模型更改时运行。它在RoleExists函数上失败并出现以下错误:System.InvalidOperationExceptionoccurredinmscorli

c# - 路由 : The current request for action [. ..] 在以下操作方法之间不明确

我有一个名为Browse.chtml的View,用户可以在其中输入搜索词,或将搜索词留空。输入搜索词时,我想将页面定向到http://localhost:62019/Gallery/Browse/{Searchterm}当没有输入任何内容时,我想将浏览器定向到http://localhost:62019/Gallery/Browse/Start/Here。当我尝试这样做时,出现错误:Thecurrentrequestforaction'Browse'oncontrollertype'GalleryController'isambiguousbetweenthefollowingacti

c# - 如何在 ASP.NET Core 中获取 HttpContext.Current?

这个问题在这里已经有了答案:AccessthecurrentHttpContextinASP.NETCore(7个答案)关闭6年前。我们目前正在使用ASP.NETCore重写/转换我们的ASP.NETWebForms应用程序。尽量避免重新设计。有一节我们在类库中使用HttpContext来检查当前状态。如何在.NETCore1.0中访问HttpContext.Current?varcurrent=HttpContext.Current;if(current==null){//dosomethinghere//stringconnection=Configuration.GetConne