草庐IT

session-config

全部标签

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# - 从 web.config 获取多个连接字符串

如何在C#中通过代码从web.config中获取所有连接字符串的名称?我试过这个:System.Configuration.ConfigurationwebConfig=System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");ConnectionStringsSectionx=webConfig.ConnectionStrings;stringhere=x.SectionInformation.Name; 最佳答案 foreach(Conn

c# - 在 App.config 中设置 WCF ClientCredentials

是否可以在App.config中为WCF设置客户端凭据?我想避免这样做:UsingsvcAsNewMyServiceClientsvc.ClientCredentials.UserName.UserName="login"svc.ClientCredentials.UserName.Password="pw"...EndUsing登录名和密码应该是配置的一部分。 最佳答案 扩展LadislavMrnka的回答,您可能会发现此实现很有用:publicclassUserNameClientCredentials:ClientCreden

c# - 在 Unity App.Config 文件中包含通用类

我有一类类型ISimpleCache我想在App.Config文件中添加为类型别名(然后是类型)线,MyApplication"/>由于显然是错误的,但是我不相信转义它们;也是对的。我目前正在拆分我的代码以使用Unity,因此距离可编译的代码库太远无法快速测试它,并希望在这里得到一些确认。 最佳答案 查看this博文:Inordertowriteagenerictype,usethe`signfollowedbythenumberofgenerictypesthattheinterface/classreceives.同一页的评论说

c# - 如何从 App.config 中读取这个自定义配置?

如何从App.config中读取这个自定义配置?而不是这个: 最佳答案 要使您的集合元素能够直接位于父元素(而不是子集合元素)中,您需要重新定义您的ConfigurationProperty。例如,假设我有一个集合元素,例如:publicclassTestConfigurationElement:ConfigurationElement{[ConfigurationProperty("name",IsKey=true,IsRequired=true)]publicstringName{get{return(string)this["

c# - 以编程方式访问 web.config 的 <compilation/> 部分?

有什么方法可以访问在web.config文件中标记?我想检查文件中的“debug”属性是否设置为“true”,但我似乎不知道该怎么做.我试过使用WebConfigurationManager,但这似乎不允许我访问部分。更新:我知道我可以像加载XML文档一样轻松地加载文件并使用XPath,但我希望框架中已经有一些东西可以为我做这件事。似乎会有一些东西,因为已经有获取应用程序设置和连接字符串的方法。我也尝试过使用WebConfigurationManager.GetSection()方法有几种:WebConfigurationManager.GetSection("compilation"

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# - session 的 Azure WebJob ServiceBusTrigger

我知道可以从服务总线队列接收消息,例如:publicstaticvoidProcessQueueMessage([ServiceBusTrigger("inputqueue")]stringmessage,TextWriterlogger)但是还有一种方法可以通过触发器属性接收session吗?类似于ServiceBusSessionTrigger?通常人们会接受这样的session:varsession=queueClient.AcceptMessageSession();但我更喜欢WebJobSDK来处理一次处理多个session的方式。编辑:似乎目前不支持:seegithubfo

c# - WCF 发现.NET 4 : Problem with config/programmatically definition

我有一个启用了发现的WCF服务,现在我想将客户端连接到它。问题:当我使用udp端点(1.)并尝试以编程方式发现服务时,它有效...当我使用App.config方法(2.)它没有(错误:未发现端点).在我看来,这两种解决方案的“udp发现结果”应该是相同的,但不幸的是它不是...1。以编程方式(有效):代码:DiscoveryClientdiscClient=newDiscoveryClient("udpDiscoveryEndpoint");FindCriteriafCriteria=newFindCriteria(typeof(IAlarmServer));fCriteria.Dur

c# - session 结束和重新启动阻止 DropDownList_SelectedIndexChanged 触发

ASP.NETsession结束和重新启动是否会干扰(阻止)下拉列表上的SelectedIndexChanged事件触发?表单正在回发,但我的断点没有被击中?在session重新启动之前一切正常。这是控件的asp:部分代码如下:protectedvoiddlSort_SelectedIndexChanged(objectsender,EventArgse){PopulateItems();//Breakpointabove-nothitaftersessionrestarts,buthitpriortosessionend.}我留下了一个空表格,因为它没有被重新填充...提前致谢中号编