草庐IT

session_is_registered

全部标签

c# - 每个应用程序 session 的 Nlog 固定文件名

我正在使用Nlog从我的C#应用程序中登录。以下是我的Nlog.config部分:对于filename我正在使用${date:format=yyyyMMdd_HHmmss}_trg.log根据创建时间命名日志。但是,当我的应用程序运行时,记录器每秒创建一个新的日志文件。如何强制Nlog修复文件名并在每个session中只创建一个日志? 最佳答案 我不确定,但我的猜测是NLog根据文件名属性(这是动态的,因为您使用的是日期布局渲染器)检查日志文件是否存在。因此,由于文件名在变化(即每次检索到的文件名值都不同(或可能不同)),NLog会

c# - 数据库错误 : There is no row at position 0

我相信几个月前有人问过这个问题,但我相信我的情况不同,同样的规则可能不适用。每次我执行这个方法都会弹出同样的错误。位置0处没有行。如果我将[0]更改为[1]或[15];[1]等处没有行。这是否意味着我的数据库甚至没有连接?我是否应该编写某种if语句来确定检查行是否存在?publicboolUpdateOrderToShipped(stringorder){orderNumber=order;stringbatch=ConfigurationManager.AppSettings["SuccessfulOrderBatch"];stringstatement="UPDATESOP1010

c# - 无效操作异常 : No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme

我正在尝试按照说明进行操作here将Cookie身份验证添加到我的网站。到目前为止,我添加了以下内容:InvoketheUseAuthenticationmethodintheConfiguremethodoftheStartup.csfile:app.UseAuthentication();InvoketheAddAuthenticationandAddCookiemethodsintheConfigureServicesmethodoftheStartup.csfile:services.AddAuthentication("MyCookieAuthenticationScheme

c# - 根据自定义条件防止个别 session 过期?

我正在做的一个网站非常以数据为中心。有些报告需要一个多小时才能完成。每当用户提交报告请求时,都会创建一个新线程来生成报告。然后用户被重定向到一个页面,上面写着报告正在进行中,请刷新以下载报告。如果用户再次刷新页面并且报告仍在进行中,则显示相同的消息;否则提供下载链接。所有报告/用户关系都保存在应用程序变量中。这工作正常,除非用户不活动超过20分钟(在处理报告时),然后用户注销;如果用户再次登录,报告仍然可以下载。我不想增加session过期时间,但如果用户在后台进行某些操作(例如正在处理报告),我需要停止过期。在Session_End中,我能够检索userid并在Application

c# - 无法检测 Session 变量是否存在

我正在尝试确定是否存在Session变量,但出现错误:System.NullReferenceException:Objectreferencenotsettoaninstanceofanobject.代码://Checkifthe"company_path"existsintheSessioncontextif(System.Web.HttpContext.Current.Session["company_path"].ToString()!=null){//Sessionexists,setitcompany_path=System.Web.HttpContext.Current.

c# -/平台 :anycpu32bitpreferred is not a valid setting for option/target:library or/target:module

我创建了一个Windows服务项目,后来决定将其输出类型更改为类库,这样我就可以将服务类包含在另一个项目中,该项目将创建要作为服务安装的.exe。但是现在,当我尝试构建第一个项目时,它失败并出现错误:/platform:anycpu32bitpreferredisnotavalidsettingforoption/target:libraryor/target:module我该如何解决这个问题? 最佳答案 尝试卸载项目(在解决方案资源管理器中右键单击)编辑.csproj(右键单击解决方案资源管理器)删除true重新加载项目。

c# - 为什么我会收到 "The modifier ' virtual'is not valid for this item“错误?

我正在尝试使用以下模型创建mvc应用程序:(代码很大。我认为它对您来说更容易理解)publicclassJob{publicintJobId{get;set;}publicstringName{get;set;}publicListGetJobs(){ListjobsList=newList();jobsList.Add(newJob{JobId=1,Name="Operator"});jobsList.Add(newJob{JobId=2,Name="Performer"});jobsList.Add(newJob{JobId=3,Name="Head"});returnjobsLi

c# - 当前上下文中不存在“ session ”

我有以下代码,它使用session但我在该行中有错误:if(Session["ShoppingCart"]==null)错误是cS0103:Thename'Session'doesnotexistinthecurrentcontext问题是什么?usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSyst

c# - 打开可空 bool 值 : case goes to null when value is true

我意识到处理可空类型的正确方法是使用HasValue属性。但我想知道为什么以下switch语句会在null情况下而不是默认情况下中断。使用VS2015C#4.0。另一台使用VS2010C#4.0的计算机没有同样的问题。privatevoidTesting(){bool?boolValue=true;switch(boolValue){casenull:break;//eventhoughvalueistrue,coderunsheredefault:break;}}编辑:观察到任何Nullable的行为如果只有caseNull和default已指定。 最佳答

c# - 打开可空 bool 值 : case goes to null when value is true

我意识到处理可空类型的正确方法是使用HasValue属性。但我想知道为什么以下switch语句会在null情况下而不是默认情况下中断。使用VS2015C#4.0。另一台使用VS2010C#4.0的计算机没有同样的问题。privatevoidTesting(){bool?boolValue=true;switch(boolValue){casenull:break;//eventhoughvalueistrue,coderunsheredefault:break;}}编辑:观察到任何Nullable的行为如果只有caseNull和default已指定。 最佳答