简体   繁体   中英

Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'

I've tried everything under the sun to get access to the AppSettings and I cannot get this to work.

I've got a class library that needs access to the web AppSettings. I've checked and there is no 'System.Collections.Specialized.NameValueCollection' to import.

Anyone got any ideas?

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);
    }}

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM