草庐IT

current_index

全部标签

c# - 异步操作后的 HttpContext.Current.Items

考虑以下ASP.NETWebAPI委托(delegate)处理程序:publicclassMyHandler:DelegatingHandler{protectedasyncoverrideTaskSendAsync(HttpRequestMessagerequest,System.Threading.CancellationTokencancellationToken){varguid=Guid.NewGuid();HttpContext.Current.Items["foo"]=guid;//AnAsyncoperationvarresult=awaitbase.SendAsync

c# - 在 Visual Studio 2012 中打开源文件时出现错误 "oldIndex must be a valid index in the Children collection"

我偶尔会在VisualStudio2012中收到带有以下错误的模态弹出窗口:oldIndexmustbeavalidindexintheChildrencollectionParametername:oldIndexActualvaluewas-1.我发现该错误的唯一引用是在thisResharperbugtrackingthread中,但我认为它与Resharper无关。在我的例子中,它似乎是在我开始调试之后发生的,并且由于某种原因调试器突然无法找到源文件,甚至在“进入”时也找不到。尝试手动打开它们失败,调试期间没有任何消息,我停止调试后出现上述消息。我(还)无法始终如一地重现这一点

c# - Application.Current.Shutdown() 没有杀死我的应用程序

我刚刚启动了一个新的C#/WPF应用程序,并且正在使用WPFContribproject中的NotifyIcon.我可以启动该程序,将“退出”菜单项添加到NotifyIcon的上下文菜单,然后将该项目链接到仅运行Application.Current.Shutdown()的方法。这会关闭主窗口和NotifyIcon,但某些东西会继续运行-从VS运行,它不会离开Debug模式。什么还在运行?或者我该如何检查?编辑我刚刚尝试添加一个调用Application.Current.Shutdown()的按钮,该按钮会正常退出。只有从NotifyIcon调用时我才会遇到问题。为什么会这样?为了澄清

c# - 在 asp.net core 中将 index.html 设置为默认页面

如何让asp.netcore为我的wwwroot中的index.html文件提供服务?我想这样做的原因是因为我正在使用AngularCLI开发一个Angular4应用程序,它负责整个构建过程。我已将其设置为构建到我的asp.net核心项目的wwwroot目录中,但asp.net核心不想为其提供服务。起初我试图通过Controller返回html文件。我试过这条路线:app.UseMvc(routes=>{routes.MapRoute(name:"default",template:"{controller=Home}/{action=Index}");});然后在Controller

c# - StringBuilder.ToString() 抛出 'Index out of range' 异常

非常感谢有人帮助我解决以下问题:我时常遇到以下异常:Indexwasoutofrange.Mustbenon-negativeandlessthanthesizeofthecollection.Parametername:chunkLength关于stringBuilder.ToString()。奇怪的是,如果我将stringBuilder.ToString()放入watch中,它会完美运行。 最佳答案 看起来这是一个多线程问题。我锁定了线程以防止同时对stringBuilder进行多次访问。publicvoidAddString(

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# - 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# - httpcontext.current.server.mappath 对象引用未设置为对象的实例

我在类中使用以下代码:stringfilePath=HttpContext.Current.Server.MapPath("~/email/teste.html");文件teste.html在文件夹中但是当它打开文件时会生成以下错误:Objectreferencenotsettoaninstanceofanobject. 最佳答案 不要使用Server.MapPath。它很慢。请改用HttpRuntime.AppDomainAppPath。只要您的网站在运行,此属性就始终可供您使用。然后像这样使用它:stringfilePath=P

c# - HttpContext.Current.Session 在 Ashx 文件中为空

我看到了一些问题(Here和Here),但它们没有回答我的问题。我正在尝试使用“ajax.ashx”文件调用Ajax,并在函数中访问Session。由于某种原因,Session对象本身的值为null。使用示例:Session=HttpContext.Current.Session//Thisisnull或者:publicvirtualvoidProcessRequest(HttpContextcontext){System.Web.SessionState.HttpSessionStateSession=context.Session;//Thisisnull}在Web.config中

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