【问题标题】:Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'无法使用 [] 将索引应用于“System.Collections.Specialized.NameValueCollection”类型的表达式
【发布时间】:2013-08-12 18:33:28
【问题描述】:

我已经尝试了所有方法来访问 AppSettings,但我无法让它工作。

我有一个需要访问网络 AppSettings 的类库。我查过了,没有 'System.Collections.Specialized.NameValueCollection' 导入。

有人有什么想法吗?

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;

public static class httpresponsebase_setoauthfromcookie
{
    public static void SetOauthFromCookie(this HttpResponseBase response, string verify,
                                          string token, string tokenSecret,
                                          string userName,
                                          bool isTwitter)
    {


        string pas =  WebConfigurationManager.AppSettings["cryptpass"],
               crypt = ((verify.Length > 3 ? (verify + ":") : "twit") + token + ":" + tokenSecret).Encrypt(pas);
        //
        var cookie = new HttpCookie(userName + (isTwitter ? "twitter" : "linkedin"), HttpServerUtility.UrlTokenEncode(Convert.FromBase64String(crypt)));
        cookie.Expires = DateTime.Now.AddDays(1);
        response.Cookies.Add(cookie);
    }}

【问题讨论】:

  • 验证您的项目没有针对客户端配置文件框架进行编译。
  • 同时发布真实代码,而不是代码的屏幕截图,这使得阅读所有相关部分变得非常困难
  • 库是根据 4.5 框架而不是客户端配置文件编译的。
  • 这还不算。我在类库中工作,并且“System.Collections.Specialized.NameValueCollection”无法导入。

标签: c# .net collections configuration


【解决方案1】:

我添加了对 System 4.0 的引用,并修复了所有问题。

【讨论】:

  • 我只有系统 2.0。我该如何解决这个问题??
猜你喜欢
  • 1970-01-01
  • 2014-01-09
  • 2018-04-03
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多