草庐IT

user_config

全部标签

c# - 单元测试项目是否可以加载目标应用程序的 app.config 文件?

我正在对使用app.config文件加载配置属性的.NET应用程序(.exe)进行单元测试。单元测试应用程序本身没有app.config文件。当我尝试对使用任何配置属性的方法进行单元测试时,它们返回null。我假设这是因为单元测试应用程序不会加载到目标应用程序的app.config中。有没有办法覆盖这个,或者我是否必须编写一个脚本来将目标app.config的内容复制到本地app.config?This帖子有点问这个问题,但作者真的是从一个与我不同的角度来看它。编辑:我应该提到我正在使用VS08TeamSystem进行单元测试。 最佳答案

c# - 如何获取当前用户,以及如何在 MVC5 中使用 User 类?

如何在MVC5中获取当前登录用户的ID?我尝试了StackOverflow的建议,但它们似乎不适用于MVC5。另外,将内容分配给用户的MVC5最佳实践是什么?(例如User应该有Items。我应该将用户的Id存储在Item中吗?我可以使用User导航属性扩展List类吗?我正在使用MVC模板中的“个人用户帐户”。试过这些:HowdoIgetthecurrentuserinanMVCApplication?HowtogetthecurrentuserinASP.NETMVCGetloggedinuser'sid-这会抛出以下内容:'Membership.GetUser()'isnull.

c# - 如何获取当前用户,以及如何在 MVC5 中使用 User 类?

如何在MVC5中获取当前登录用户的ID?我尝试了StackOverflow的建议,但它们似乎不适用于MVC5。另外,将内容分配给用户的MVC5最佳实践是什么?(例如User应该有Items。我应该将用户的Id存储在Item中吗?我可以使用User导航属性扩展List类吗?我正在使用MVC模板中的“个人用户帐户”。试过这些:HowdoIgetthecurrentuserinanMVCApplication?HowtogetthecurrentuserinASP.NETMVCGetloggedinuser'sid-这会抛出以下内容:'Membership.GetUser()'isnull.

c# - {"<user xmlns=' '> 不是预期的。} 反序列化 Twitter XML

我正在通过OAuth从Twitter中提取XML。我正在向http://twitter.com/account/verify_credentials.xml发出请求,它返回以下XML:16434938LloydSparkeslloydsparkesHockley,Essex,UKStudenthttp://a3.twimg.com/profile_images/351849613/twitterProfilePhoto_normal.jpghttp://www.lloydsparkes.co.ukfalse1159fdaf4000000220f7bFFF7CCF2E19587WedSe

c# - {"<user xmlns=' '> 不是预期的。} 反序列化 Twitter XML

我正在通过OAuth从Twitter中提取XML。我正在向http://twitter.com/account/verify_credentials.xml发出请求,它返回以下XML:16434938LloydSparkeslloydsparkesHockley,Essex,UKStudenthttp://a3.twimg.com/profile_images/351849613/twitterProfilePhoto_normal.jpghttp://www.lloydsparkes.co.ukfalse1159fdaf4000000220f7bFFF7CCF2E19587WedSe

c# - 从 web.config 中读取连接字符串

如何将连接字符串从web.config文件读取到包含在类库中的公共(public)类中?我试过:WebConfigurationManagerConfigurationManager但是这些类在我的类库中不被识别。 最佳答案 您需要添加对System.Configuration的引用,然后使用:System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

c# - 从 web.config 中读取连接字符串

如何将连接字符串从web.config文件读取到包含在类库中的公共(public)类中?我试过:WebConfigurationManagerConfigurationManager但是这些类在我的类库中不被识别。 最佳答案 您需要添加对System.Configuration的引用,然后使用:System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

c# - 使用 ConfigurationManager 从 Web.Config 读取 key

我正在尝试从与Web层不同的层中的Web.config文件中读取key(相同的解决方案)这是我正在尝试的:stringuserName=System.Configuration.ConfigurationManager.AppSettings["PFUserName"];stringpassword=System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];这是我在Web.config文件中的appSettings:........当我调试代码时username和password只是null,所以它没有获取键

c# - 使用 ConfigurationManager 从 Web.Config 读取 key

我正在尝试从与Web层不同的层中的Web.config文件中读取key(相同的解决方案)这是我正在尝试的:stringuserName=System.Configuration.ConfigurationManager.AppSettings["PFUserName"];stringpassword=System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];这是我在Web.config文件中的appSettings:........当我调试代码时username和password只是null,所以它没有获取键

c# - 从 .NET 中的 app.config 或 web.config 读取设置

我正在开发一个C#类库,它需要能够从web.config或app.config文件中读取设置(取决于DLL是否从ASP.NETWeb应用程序或Windows窗体应用程序引用)。我发现了ConfigurationSettings.AppSettings.Get("MySetting")有效,但该代码已被Microsoft标记为已弃用。我读过我应该使用:ConfigurationManager.AppSettings["MySetting"]但是,System.Configuration.ConfigurationManager类在C#类库项目中似乎不可用。执行此操作的最佳方法是什么?