草庐IT

current_tags

全部标签

c# - 为什么 HttpContext.Current 为空?

我有一个在所有应用程序中使用的值;我在application_start中设置了这个voidApplication_Start(objectsender,EventArgse){Dictionary>Panels=newDictionary>();Listsetting=clsPanelSettingFactory.GetAll();foreach(clsPanelSettingpanelinsetting){Panels.Add(panel.AdminId,newList(){panel.Phone,panel.UserName,panel.Password});}Applicati

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# - 从不同线程访问 HttpContext.Current

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

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# - 路由 : 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 MVC 中选择 Tag Helper

我需要有关ASP.NETCore中的select标记助手的一些帮助。我有一个我试图绑定(bind)到选择标签助手的员工列表。我的员工在ListEmployeesList并且选定的值将进入EmployeeId属性(property)。我的View模型如下所示:publicclassMyViewModel{publicintEmployeeId{get;set;}publicstringComments{get;set;}publicListEmployeesList{get;set;}}我的员工类(class)如下所示:publicclassEmployee{publicintId{ge

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

c# - 在测试初始化​​方法中模拟 HttpContext.Current

我正在尝试将单元测试添加到我构建的ASP.NETMVC应用程序中。在我的单元测试中,我使用以下代码:[TestMethod]publicvoidIndexAction_Should_Return_View(){varcontroller=newMembershipController();controller.SetFakeControllerContext("TestUser");...}使用以下助手来模拟Controller上下文:publicstaticclassFakeControllerContext{publicstaticHttpContextBaseFakeHttpCo

c# - 在单元测试中设置 HttpContext.Current.Session

我有一个网络服务,我正在尝试对其进行单元测试。在服务中,它从HttpContext中提取几个值,如下所示:m_password=(string)HttpContext.Current.Session["CustomerId"];m_userID=(string)HttpContext.Current.Session["CustomerUrl"];在单元测试中,我使用简单的工作请求创建上下文,如下所示:SimpleWorkerRequestrequest=newSimpleWorkerRequest("","","",null,newStringWriter());HttpContext

javascript - 将 defer 属性添加到 javascript_include_tag Rails

有什么方法可以添加defer使用javascript_include_tag轻松设置属性Rails中的助手?即,是否有一些简单的方法可以转向进入 最佳答案 "defer"%>这将使您(在开发中): 关于javascript-将defer属性添加到javascript_include_tagRails,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/10982375/