0

嗨,我在 C# 中实现了以下代码,用于捕获标头属性。出于某种原因,我只获取名字的数据,其余字段显示为空。我知道它们有值,但由于某种原因,它们显示为空。

// Load ServerVariable collection into NameValueCollection object.
            System.Collections.Specialized.NameValueCollection headerdetails = Request.Headers;

            List<string> requiredHeaders = new List<string>();
            requiredHeaders.Add("FirstName");
            requiredHeaders.Add("MiddleName");
            requiredHeaders.Add("LastName");
            requiredHeaders.Add("email");


            // Get names of all keys into a string array. 
            String[] arr1 = headerdetails.AllKeys;
            for (int i = 0; i < arr1.Length; i++)
            {
                if (requiredHeaders.Contains(arr1[i]))
                {

                    if (arr1[i] == "FirstName")
                    {
                        String[] arr2 = headerdetails.GetValues(arr1[i]);
                        for (int values = 0; values < arr2.Length; values++)
                        {
                            string firstname = Server.HtmlEncode(arr2[values]);
                            Session["firstName"] = firstname;
                        }
                    }
                    if (arr1[i] == "MiddleName")
                    {
                        String[] arr2 = headerdetails.GetValues(arr1[i]);
                        for (int values = 0; values < arr2.Length; values++)
                        {
                            string middlename = Server.HtmlEncode(arr2[values]);
                            Session["middleName"] = middlename;
                        }
                    }
                    if (arr1[i] == "LastName")
                    {
                        String[] arr2 = headerdetails.GetValues(arr1[i]);
                        for (int values = 0; values < arr2.Length; values++)
                        {
                            string lastname = Server.HtmlEncode(arr2[values]);
                            Session["lastName"] = lastname;
                        }
                    }
                    if (arr1[i] == "email")
                    {
                        String[] arr2 = headerdetails.GetValues(arr1[i]);
                        for (int values = 0; values < arr2.Length; values++)
                        {
                            string email = Server.HtmlEncode(arr2[values]);
                            Session["emailID"] = email;
                        }
                    }
4

1 回答 1

1

Alrite伙计们,我发现了我的错误。笨蛋,在循环中有一个 response.redirect,因此我只得到了第一个名字。PS:注意自我-不要长时间自我工作。

于 2013-07-16T15:48:37.087 回答