当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.GetKey方法代码示例

本文整理汇总了C#中NameValueCollection.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.GetKey方法的具体用法?C# NameValueCollection.GetKey怎么用?C# NameValueCollection.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NameValueCollection的用法示例。


在下文中一共展示了NameValueCollection.GetKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyFormToDict

    public static Dictionary<string, object> CopyFormToDict(NameValueCollection nv, string[] deleteItems)
    {
        Dictionary<string, object> dict = new Dictionary<string, object>();

        for (int i = 0; i < nv.Count; i++)
        {
            bool toDelete = false;
            if (deleteItems != null)
            {
                foreach (string item in deleteItems)
                {
                    if (item == nv.GetKey(i))
                    {
                        toDelete = true;
                        break;
                    }
                }
            }
            if (toDelete) continue;

            dict.Add(nv.GetKey(i), nv.Get(i));
        }
        return dict;
    }
开发者ID:honj51,项目名称:ideacode,代码行数:24,代码来源:Common.cs

示例2: Initialize

    public override void Initialize(string name,
                                    NameValueCollection config)
    {
// Verify that config isn't null
        if (config == null)
            throw new ArgumentNullException("config");
// Assign the provider a default name if it doesn't have one
        if (String.IsNullOrEmpty(name))
            name = "TextFileWebEventProvider";
// Add a default "description" attribute to config if the
// attribute doesn't exist or is empty
        if (string.IsNullOrEmpty(config["description"]))
        {
            config.Remove("description");
            config.Add("description", "Text file Web event provider");
        }
// Call the base class's Initialize method
        base.Initialize(name, config);
// Initialize _LogFileName and make sure the path
// is app-relative
        string path = config["logFileName"];
        if (String.IsNullOrEmpty(path))
            throw new ProviderException
                ("Missing logFileName attribute");
        if (!VirtualPathUtility.IsAppRelative(path))
            throw new ArgumentException
                ("logFileName must be app-relative");
        string fullyQualifiedPath = VirtualPathUtility.Combine
            (VirtualPathUtility.AppendTrailingSlash
                 (HttpRuntime.AppDomainAppVirtualPath), path);
        _LogFileName = HostingEnvironment.MapPath(fullyQualifiedPath);
        config.Remove("logFileName");
// Make sure we have permission to write to the log file
// throw an exception if we don't
        FileIOPermission permission =
            new FileIOPermission(FileIOPermissionAccess.Write |
                                 FileIOPermissionAccess.Append, _LogFileName);
        permission.Demand();
// Throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
            string attr = config.GetKey(0);
            if (!String.IsNullOrEmpty(attr))
                throw new ProviderException
                    ("Unrecognized attribute: " + attr);
        }
    }
开发者ID:fgq841103,项目名称:spring-net,代码行数:47,代码来源:TextFileWebEventProvider.cs

示例3: Add

        public void Add()
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            Assert.False(nameValueCollection.HasKeys());
            for (int i = 0; i < 10; i++)
            {
                string name = "Name_" + i;
                string value = "Value_" + i;
                nameValueCollection.Add(name, value);
                Assert.Equal(i + 1, nameValueCollection.Count);
                Assert.Equal(i + 1, nameValueCollection.AllKeys.Length);
                Assert.Equal(i + 1, nameValueCollection.Keys.Count);

                // We should be able to access values by the name
                Assert.Equal(value, nameValueCollection[name]);
                Assert.Equal(value, nameValueCollection.Get(name));

                Assert.Contains(name, nameValueCollection.AllKeys);
                Assert.Contains(name, nameValueCollection.Keys.Cast<string>());

                Assert.Equal(new string[] { value }, nameValueCollection.GetValues(name));

                // Get(string), GetValues(string) and this[string] should be case insensitive
                Assert.Equal(value, nameValueCollection[name.ToUpperInvariant()]);
                Assert.Equal(value, nameValueCollection[name.ToLowerInvariant()]);

                Assert.Equal(value, nameValueCollection.Get(name.ToUpperInvariant()));
                Assert.Equal(value, nameValueCollection.Get(name.ToLowerInvariant()));

                Assert.Equal(new string[] { value }, nameValueCollection.GetValues(name.ToUpperInvariant()));
                Assert.Equal(new string[] { value }, nameValueCollection.GetValues(name.ToLowerInvariant()));

                Assert.DoesNotContain(name.ToUpperInvariant(), nameValueCollection.AllKeys);
                Assert.DoesNotContain(name.ToLowerInvariant(), nameValueCollection.AllKeys);

                Assert.DoesNotContain(name.ToUpperInvariant(), nameValueCollection.Keys.Cast<string>());
                Assert.DoesNotContain(name.ToLowerInvariant(), nameValueCollection.Keys.Cast<string>());

                // We should be able to access values and keys in the order they were added
                Assert.Equal(value, nameValueCollection[i]);
                Assert.Equal(value, nameValueCollection.Get(i));
                Assert.Equal(name, nameValueCollection.GetKey(i));
                Assert.Equal(new string[] { value }, nameValueCollection.GetValues(i));
            }
            Assert.True(nameValueCollection.HasKeys());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:46,代码来源:NameValueCollection.AddStringStringTests.cs

示例4: Initialize

 // BlogsaRoleProvider methods
 public override void Initialize(string name, NameValueCollection config)
 {
     if (config == null)
         throw new ArgumentNullException("config");
     if (String.IsNullOrEmpty(name))
         name = "SITRoleProvider";
     if (string.IsNullOrEmpty(config["description"]))
     {
         config.Remove("description");
         config.Add("description", "SIT Role Provider");
     }
     base.Initialize(name, config);
     //FileIOPermission permission =
     //    new FileIOPermission(FileIOPermissionAccess.Read,
     //    _XmlFileName);
     //permission.Demand();
     if (config.Count > 0)
     {
         string attr = config.GetKey(0);
         if (!String.IsNullOrEmpty(attr))
             throw new ProviderException
                 ("Unrecognized attribute: " + attr);
     }
 }
开发者ID:jawedkhan,项目名称:paharibaba,代码行数:25,代码来源:Providers.cs

示例5: Add_NullName

        public void Add_NullName()
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            string value = "value";
            nameValueCollection.Add(null, value);
            Assert.Equal(1, nameValueCollection.Count);
            Assert.Equal(1, nameValueCollection.AllKeys.Length);
            Assert.Equal(1, nameValueCollection.Keys.Count);

            Assert.Contains(null, nameValueCollection.AllKeys);
            Assert.Contains(null, nameValueCollection.Keys.Cast<string>());

            Assert.Equal(value, nameValueCollection[null]);
            Assert.Equal(value, nameValueCollection.Get(null));

            Assert.Equal(value, nameValueCollection[0]);
            Assert.Equal(value, nameValueCollection.Get(0));

            Assert.Equal(new string[] { value }, nameValueCollection.GetValues(null));
            Assert.Equal(new string[] { value }, nameValueCollection.GetValues(0));

            Assert.Null(nameValueCollection.GetKey(0));
            Assert.False(nameValueCollection.HasKeys());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:24,代码来源:NameValueCollection.AddStringStringTests.cs

示例6: ViewContentProperties


//.........这里部分代码省略.........
        }

        //GET PROPERTY: smart form title
        string typeValue;
        if (!(data.XmlConfiguration == null))
        {
            typeValue = (string)("&nbsp;" + data.XmlConfiguration.Title);
            xml_id = data.XmlConfiguration.Id;
        }
        else
        {
            typeValue = (string)(m_refMsg.GetMessage("none specified msg") + " " + m_refMsg.GetMessage("html content assumed"));
        }

        if (folder_data == null)
        {
            folder_data = m_refContentApi.EkContentRef.GetFolderById(content_data.FolderId);
        }

        //GET PROPERTY: template name
        string fileName;
        if (m_refContent.MultiConfigExists(content_data.Id, m_refContentApi.RequestInformationRef.ContentLanguage))
        {
            TemplateData t_templateData = m_refContent.GetMultiTemplateASPX(content_data.Id);
            if (t_templateData != null)
            {
                fileName = t_templateData.FileName;
            }
            else
            {
                fileName = folder_data.TemplateFileName;
            }
        }
        else
        {
            fileName = folder_data.TemplateFileName;
        }

        //GET PROPERTY: rating
        string rating;
        Collection dataCol = m_refContentApi.GetContentRatingStatistics(data.Id, 0, null);
        int total = 0;
        int sum = 0;
        int hits = 0;
        if (dataCol.Count > 0)
        {
            total = Convert.ToInt32 (dataCol["total"]);
            sum = Convert.ToInt32 (dataCol["sum"]);
            hits = Convert.ToInt32 (dataCol["hits"]);
        }
        if (total == 0)
        {
            rating = m_refMsg.GetMessage("content not rated");
        }
        else
        {
            rating = System.Convert.ToString(Math.Round(System.Convert.ToDouble(Convert.ToDouble((short)sum) / total), 2));
        }

        NameValueCollection contentPropertyValues = new NameValueCollection();
        contentPropertyValues.Add(m_refMsg.GetMessage("content title label"), data.Title);
        contentPropertyValues.Add(m_refMsg.GetMessage("content id label"), data.Id.ToString ());
        contentPropertyValues.Add(m_refMsg.GetMessage("content language label"), LanguageName);
        contentPropertyValues.Add(m_refMsg.GetMessage("content status label"), dataStatus);
        contentPropertyValues.Add(m_refMsg.GetMessage("content LUE label"), data.EditorFirstName + " " + data.EditorLastName);
        contentPropertyValues.Add(m_refMsg.GetMessage("content LED label"), Ektron.Cms.Common.EkFunctions.FormatDisplayDate(data.DisplayLastEditDate, data.LanguageId));
        contentPropertyValues.Add(m_refMsg.GetMessage("generic start date label"),(goLive == Ektron.Cms.Common.EkFunctions.FormatDisplayDate(DateTime.MinValue.ToString(), data.LanguageId) ? m_refMsg.GetMessage("none specified msg") : goLive ));
        contentPropertyValues.Add(m_refMsg.GetMessage("generic end date label"), (endDate == Ektron.Cms.Common.EkFunctions.FormatDisplayDate(DateTime.MinValue.ToString(),  data.LanguageId) ? m_refMsg.GetMessage("none specified msg") : endDate));
        contentPropertyValues.Add(m_refMsg.GetMessage("End Date Action Title"), endDateActionTitle);
        contentPropertyValues.Add(m_refMsg.GetMessage("content DC label"), Ektron.Cms.Common.EkFunctions.FormatDisplayDate(data.DateCreated.ToString(), data.LanguageId));
        contentPropertyValues.Add(m_refMsg.GetMessage("lbl approval method"), apporvalMethod);
        contentPropertyValues.Add(m_refMsg.GetMessage("content approvals label"), approvallist.ToString());
        if (content_data.Type == Ektron.Cms.Common.EkConstants.CMSContentType_CatalogEntry || content_data.Type == Ektron.Cms.Common.EkConstants.CMSContentType_Content || content_data.Type == Ektron.Cms.Common.EkConstants.CMSContentType_Forms)
        {
            contentPropertyValues.Add(type, typeValue);
        }
        if (content_data.Type == Ektron.Cms.Common.EkConstants.CMSContentType_CatalogEntry || content_data.Type == 1 || content_data.Type == 2 || content_data.Type == 104)
        {
            contentPropertyValues.Add(m_refMsg.GetMessage("template label"), fileName);
        }
        contentPropertyValues.Add(m_refMsg.GetMessage("generic Path"), data.Path);
        contentPropertyValues.Add(m_refMsg.GetMessage("rating label"), rating);
        contentPropertyValues.Add(m_refMsg.GetMessage("lbl content searchable"), data.IsSearchable.ToString());

        //string[] endColon = new string[] { ":" };
        string endColon = ":";
        string propertyName;
        StringBuilder propertyRows = new StringBuilder();
        for (i = 0; i <= contentPropertyValues.Count - 1; i++)
        {
            propertyName = (string)(contentPropertyValues.GetKey(i).TrimEnd(endColon.ToString().ToCharArray()));
            propertyRows.Append("<tr><td class=\"label\">");
            propertyRows.Append(propertyName + ":");
            propertyRows.Append("</td><td>");
            propertyRows.Append(contentPropertyValues[contentPropertyValues.GetKey(i)]);
            propertyRows.Append("</td></tr>");
        }

        litPropertyRows.Text = propertyRows.ToString();
    }
开发者ID:jaytem,项目名称:minGit,代码行数:101,代码来源:viewcontent.ascx.cs

示例7: runTest

 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     NameValueCollection nvc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aA",
         "text",
         "     SPaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     string [] keys = 
     {
         "zero",
         "oNe",
         " ",
         "",
         "aa",
         "1",
         System.DateTime.Today.ToString(),
         "$%^#",
         Int32.MaxValue.ToString(),
         "     spaces",
         "2222222222222222222222222"
     };
     int cnt = 0;            
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         nvc = new NameValueCollection();
         Console.WriteLine("1. GetKey() on empty collection");
         iCountTestcases++;
         Console.WriteLine("     - GetKey(-1)");
         try 
         {
             nvc.GetKey(-1);
             iCountErrors++;
             Console.WriteLine("Err_0001a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString());
         }
         iCountTestcases++;
         Console.WriteLine("     - GetKey(0)");
         try 
         {
             nvc.GetKey(0);
             iCountErrors++;
             Console.WriteLine("Err_0001c, no exception");
         }
         catch (ArgumentException ex) 
         {
             Console.WriteLine("  Expected exception: {0}", ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_001d, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. add simple strings access them via GetKey()");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         cnt = nvc.Count;
         int len = values.Length;
         for (int i = 0; i < len; i++) 
         {
             nvc.Add(keys[i], values[i]);
         }
         if (nvc.Count != len) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
         } 
         for (int i = 0; i < len; i++) 
         {
             iCountTestcases++;
             if ( String.Compare(nvc.GetKey(i), keys[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}b, returned: \"{1}\", expected \"{2}\"", i, nvc.GetKey(i), keys[i]);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8727getkey_int.cs

示例8: Initialize

    public override void Initialize(string name, NameValueCollection config)
    {
        // Verify that config isn't null
        if (config == null)	throw new ArgumentNullException("config");

        // Assign the provider a default name if it doesn't have one
        if (String.IsNullOrEmpty(name))	name = "TextFileProfileProvider";

        // Add a default "description" attribute to config if the
        // attribute doesn't exist or is empty
        if (string.IsNullOrEmpty(config["description"]))
        {
            config.Remove("description");
            config.Add("description", "Text file profile provider");
        }

        // Call the base class's Initialize method
        base.Initialize(name, config);

        // Throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
            string attr = config.GetKey(0);
            if (!String.IsNullOrEmpty(attr))	throw new ProviderException("Unrecognized attribute: " + attr);
        }

        // Make sure we can read and write files
        // in the Profile_Data directory
        FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, AbsoluteProfileFilePath);
        permission.Demand();
    }
开发者ID:benkitzelman,项目名称:ProfilePersistence,代码行数:31,代码来源:TextFileProfileProvider.cs

示例9: Initialize

    public override void Initialize(String name, NameValueCollection config)
    {
        // if the parameter name is empty, use the default name
        if (name == null || name.Trim() == String.Empty)
        {
            name = _name;
        }

        // if no configuration attributes found, throw an exception
        if (config == null)
        {
            throw new ArgumentNullException("config", "There are no configuration attributes in web.config!");
        }

        // if no 'description' attribute in the configuration, use the default
        String cfg_description = config["description"];
        if (cfg_description == null || cfg_description.Trim() == "")
        {
            config.Remove("description");
            config.Add("description", _description);
        }

        // if there is no 'connectionStringName' in the configuration, throw an exception
        // otherwise extract the connection string from the web.config
        // and test it, if it is not working throw an exception
        String cfg_connectionStringName = config["connectionStringName"];
        if (cfg_connectionStringName == null || cfg_connectionStringName.Trim() == "")
        {
            throw new ProviderException("Provider configuration attribute 'connectionStringName' in web.config is missing or blank!");
        }
        else
        {
            // get the entry refrenced by the 'connectionStringName'
            ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[cfg_connectionStringName];

            // if you can't find the entry defined by the 'connectionStringName' or it is empty, throw an exception
            if (connObj != null && connObj.ConnectionString != null && connObj.ConnectionString.Trim() != "")
            {
                try
                {
                    // try testing the connection
                    using (SqlConnection conn = new SqlConnection(connObj.ConnectionString))
                    {
                        conn.Open();
                        _connectionStringName = connObj.ConnectionString;
                    }
                }
                catch (Exception e)
                {
                    // if anything wrong happened, throw an exception showing what happened
                    ProviderException pException = new ProviderException(
                        String.Format("Connection string '{0}' in web.config is not usable!", cfg_connectionStringName), e);

                    throw pException;
                }
            }
            else
            {
                throw new ProviderException(String.Format("Connection string '{0}' in web.config is missing or blank!",
                    cfg_connectionStringName));
            }
        }

        // if there is no 'commandTimeout' attribute in the configuration, use the default
        // otherwise try to get it, if errors ocurred, throw an exception
        String cfg_commandTimeout = config["commandTimeout"];
        if (cfg_commandTimeout == null || cfg_commandTimeout.Trim() == String.Empty)
        {

        }
        else
        {
            Int32 _ct;

            if (Int32.TryParse(cfg_commandTimeout, out _ct) && _ct >= 0)
            {
                _commandTimeout = _ct;
            }
            else
            {
                throw new ProviderException("Provider property 'commandTimeout' in web.config is not valid!");
            }
        }

        // initialize the SqlProfileProvider with the current parameters
        base.Initialize(name, config);

        // throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
            String strAttributes = "";

            for (int i = 0; i < config.Count; i++)
            {
                strAttributes += config.GetKey(i);

                if (i < config.Count - 1)
                {
                    strAttributes += ", ";
                }
//.........这里部分代码省略.........
开发者ID:kimx,项目名称:UserProfilerLabs,代码行数:101,代码来源:SearchableSqlProfileProvider.cs

示例10: Initialize

    public override void Initialize(string name, NameValueCollection config)
    {
        if (config == null)
                throw new ArgumentNullException("config");
            if (String.IsNullOrEmpty(name))
                name = "SqlTableProfileProvider";
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "SqlTableProfileProvider");
            }
            base.Initialize(name, config);

            string temp = config["connectionStringName"];
            if (String.IsNullOrEmpty(temp))
                throw new ProviderException("connectionStringName not specified");
            _connStr = ConfigurationManager.ConnectionStrings["SnitzConnectionString"].ConnectionString;
            if (String.IsNullOrEmpty(_connStr))
            {
                throw new ProviderException("connectionStringName not specified");
            }

            _appName = config["applicationName"];
            if (string.IsNullOrEmpty(_appName))
                _appName = "/";

            if (_appName.Length > 256)
            {
                throw new ProviderException("Application name too long");
            }

            _table = config["table"];
            if (string.IsNullOrEmpty(_table))
            {
                throw new ProviderException("No table specified");
            }
            EnsureValidTableOrColumnName(_table);

            string timeout = config["commandTimeout"];
            if (string.IsNullOrEmpty(timeout) || !Int32.TryParse(timeout, out _commandTimeout))
            {
                _commandTimeout = 30;
            }

            config.Remove("commandTimeout");
            config.Remove("connectionStringName");
            config.Remove("applicationName");
            config.Remove("table");
            if (config.Count > 0)
            {
                string attribUnrecognized = config.GetKey(0);
                if (!String.IsNullOrEmpty(attribUnrecognized))
                    throw new ProviderException("Unrecognized config attribute:" + attribUnrecognized);
            }
    }
开发者ID:huwred,项目名称:SnitzDotNet,代码行数:55,代码来源:SnitzProfileProvider.cs

示例11: Initialize

    public override void Initialize(string name, NameValueCollection config)
    {
        // Verify that config isn't null
        if (config == null)
            throw new ArgumentNullException("config");

        // Assign the provider a default name if it doesn't have one
        if (String.IsNullOrEmpty(name))
            name = "SqlSiteMapProvider";

        // Add a default "description" attribute to config if the
        // attribute doesn?t exist or is empty
        if (string.IsNullOrEmpty(config["description"]))
        {
            config.Remove("description");
            config.Add("description", "SQL site map provider");
        }

        // Call the base class's Initialize method
        base.Initialize(name, config);

        // Initialize _connect
        string connect = config["connectionStringName"];

        if (String.IsNullOrEmpty(connect))
            throw new ProviderException(_errmsg5);

        config.Remove("connectionStringName");

        if (WebConfigurationManager.ConnectionStrings[connect] == null)
            throw new ProviderException(_errmsg6);

        _connect = WebConfigurationManager.ConnectionStrings[connect].ConnectionString;

        if (String.IsNullOrEmpty(_connect))
            throw new ProviderException(_errmsg7);

        // Initialize SQL cache dependency info
        string dependency = config["sqlCacheDependency"];

        if (!String.IsNullOrEmpty(dependency))
        {
            if (String.Equals(dependency, "CommandNotification", StringComparison.InvariantCultureIgnoreCase))
            {

                SqlDependency.Start(_connect);
                _2005dependency = true;
            }
            else
            {
                // If not "CommandNotification", then extract database and table names
                string[] info = dependency.Split(new char[] { ':' });
                if (info.Length != 2)
                    throw new ProviderException(_errmsg8);

                _database = info[0];
                _table = info[1];
            }

            config.Remove("sqlCacheDependency");
        }

        // SiteMapProvider processes the securityTrimmingEnabled
        // attribute but fails to remove it. Remove it now so we can
        // check for unrecognized configuration attributes.

        if (config["securityTrimmingEnabled"] != null)
            config.Remove("securityTrimmingEnabled");

        // Throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
            string attr = config.GetKey(0);
            if (!String.IsNullOrEmpty(attr))
                throw new ProviderException("Unrecognized attribute: " + attr);
        }
    }
开发者ID:nateo,项目名称:Project1,代码行数:77,代码来源:SqlSiteMapProvider.cs

示例12: Initialize

    public override void Initialize(string name, NameValueCollection config)
    {
        if (config == null)
          throw new ArgumentNullException("config");

        if (String.IsNullOrEmpty(name))
          name = "XmlMembershipProvider";

        if (string.IsNullOrEmpty(config["description"]))
        {
          config.Remove("description");
          config.Add("description", "XML membership provider");
        }

        base.Initialize(name, config);

        // Initialize _XmlFileName and make sure the path
        // is app-relative
        string path = config["xmlFileName"];

        if (String.IsNullOrEmpty(path))
          path = "~/admin/Users.xml";

        if (!VirtualPathUtility.IsAppRelative(path))
          throw new ArgumentException
          ("xmlFileName must be app-relative");

        string fullyQualifiedPath = VirtualPathUtility.Combine
        (VirtualPathUtility.AppendTrailingSlash
        (HttpRuntime.AppDomainAppVirtualPath), path);

        _XmlFileName = HostingEnvironment.MapPath(fullyQualifiedPath);
        config.Remove("xmlFileName");

        // Make sure we have permission to read the XML data source and
        // throw an exception if we don't
        FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, _XmlFileName);
        permission.Demand();

        // Throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
          string attr = config.GetKey(0);
          if (!String.IsNullOrEmpty(attr))
        throw new ProviderException("Unrecognized attribute: " + attr);
        }
    }
开发者ID:carlozzer,项目名称:InventioEngine,代码行数:47,代码来源:XmlMembershipProvider.cs

示例13: Initialize

    // MembershipProvider Methods
    public override void Initialize(string name, NameValueCollection config)
    {
        // Verify that config isn't null
        if (config == null)
        {
          throw new ArgumentNullException("config");
        }

        // Assign the provider a default name if it doesn't have one
        if (String.IsNullOrEmpty(name))
        {
          name = "XmlMembershipProvider";
        }

        // Add a default "description" attribute to config if the
        // attribute doesn’t exist or is empty
        if (string.IsNullOrEmpty(config["description"]))
        {
          config.Remove("description");
          config.Add("description", "XML membership provider");
        }

        // Call the base class's Initialize method
        base.Initialize(name, config);

        // Initialize xmlFileName and make sure the path is app-relative
        string path = config["xmlFileName"];

        if (String.IsNullOrEmpty(path))
        {
          path = "~/App_Data/Users.xml";
        }

        if (!VirtualPathUtility.IsAppRelative(path))
        {
          throw new ArgumentException(Resources.Common.XMLFileNameMustBeAppRelative);
        }

        string fullyQualifiedPath = VirtualPathUtility.Combine
        (VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), path);

        this.xmlFileName = HostingEnvironment.MapPath(fullyQualifiedPath);
        config.Remove("xmlFileName");

        // Make sure we have permission to read the XML data source and
        // throw an exception if we don't
        FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, this.xmlFileName);
        permission.Demand();

        // Throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
          string attr = config.GetKey(0);
          if (!String.IsNullOrEmpty(attr))
          {
        throw new ProviderException(Resources.Common.UnrecognizedAttribute + attr);
          }
        }
    }
开发者ID:josekpaul,项目名称:LinkedInDeveloperToolkit,代码行数:60,代码来源:XmlMembershipProvider.cs

示例14: Initialize

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="config"></param>
    public override void Initialize(string name, NameValueCollection config)
    {
        if (config == null)
                throw new ArgumentNullException("config");

            if (String.IsNullOrEmpty(name))
                name = "XmlMembershipProvider";

            if (Type.GetType("Mono.Runtime") != null) {
                // Mono dies with a "Unrecognized attribute: description" if a description is part of the config.
                if (!string.IsNullOrEmpty(config["description"])) {
                    config.Remove("description");
                }
            } else {
                if (string.IsNullOrEmpty(config["description"])) {
                    config.Remove("description");
                    config.Add("description", "XML membership provider");
                }
            }

            base.Initialize(name, config);

            // Initialize _XmlFileName and make sure the path
            // is app-relative
            string path = config["xmlFileName"];

            if (String.IsNullOrEmpty(path))
            {
                path = DataIO.UsersLocation;
            }
                //path = BlogSettings.Instance.StorageLocation + "users.xml";

            if (!VirtualPathUtility.IsAppRelative(path))
                throw new ArgumentException
                    ("xmlFileName must be app-relative");

            string fullyQualifiedPath = VirtualPathUtility.Combine
                (VirtualPathUtility.AppendTrailingSlash
                (HttpRuntime.AppDomainAppVirtualPath), path);

            _XmlFileName = HostingEnvironment.MapPath(fullyQualifiedPath);
            config.Remove("xmlFileName");

            // Make sure we have permission to read the XML data source and
            // throw an exception if we don't
            FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, _XmlFileName);
            permission.Demand();

            //Password Format
            if (config["passwordFormat"] == null)
            {
                config["passwordFormat"] = "Hashed";
                passwordFormat = MembershipPasswordFormat.Hashed;
            }
            else if (String.Compare(config["passwordFormat"], "clear", true) == 0)
            {
                passwordFormat = MembershipPasswordFormat.Clear;
            }
            else
            {
                passwordFormat = MembershipPasswordFormat.Hashed;
            }
            config.Remove("passwordFormat");

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0) {
                string attr = config.GetKey(0);
                if (!String.IsNullOrEmpty(attr))
                    throw new ProviderException("Unrecognized attribute: " + attr);
            }
    }
开发者ID:philippkueng,项目名称:hammyoncoffeine,代码行数:76,代码来源:XmlMembershipProvider.cs

示例15: Add_NullValue

        public void Add_NullValue()
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            string name = "name";
            nameValueCollection.Add(name, null);
            Assert.Equal(1, nameValueCollection.Count);
            Assert.Equal(1, nameValueCollection.AllKeys.Length);
            Assert.Equal(1, nameValueCollection.Keys.Count);

            Assert.Contains(name, nameValueCollection.AllKeys);
            Assert.Contains(name, nameValueCollection.Keys.Cast<string>());

            Assert.Null(nameValueCollection[name]);
            Assert.Null(nameValueCollection.Get(name));

            Assert.Null(nameValueCollection[0]);
            Assert.Null(nameValueCollection.Get(0));

            Assert.Null(nameValueCollection.GetValues(name));
            Assert.Null(nameValueCollection.GetValues(0));

            Assert.Equal(name, nameValueCollection.GetKey(0));
            Assert.True(nameValueCollection.HasKeys());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:24,代码来源:NameValueCollection.AddStringStringTests.cs


注:本文中的NameValueCollection.GetKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。