Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP.NET中的web应用程序中使用多个cookie_C#_Asp.net_Cookies - Fatal编程技术网

C# 在ASP.NET中的web应用程序中使用多个cookie

C# 在ASP.NET中的web应用程序中使用多个cookie,c#,asp.net,cookies,C#,Asp.net,Cookies,我的web应用程序中有cookie来存储用户语言。 我创建了这个cookie 应用程序\u开始请求&应用程序\u开始 在my global.asax文件中,使用以下代码: Response.Cookies["IPortalCookies"]["Language"] = "en"; Response.Cookies["IPortalCookies"]["Direction"] = "ltr"; Resp

我的web应用程序中有cookie来存储用户语言。 我创建了这个cookie

应用程序\u开始请求&应用程序\u开始

在my global.asax文件中,使用以下代码:

Response.Cookies["IPortalCookies"]["Language"] = "en";
                        Response.Cookies["IPortalCookies"]["Direction"] = "ltr";
                        Response.Cookies["IPortalCookies"].Expires = DateTime.Now.AddYears(1);
现在,我需要创建另一个cookie来存储每个用户的喜好:

int articleid = Convert.ToInt32(e.CommandArgument);
        //    var _ah = new ArticlesHelper();
        //    if (Request.Cookies["IPortalCookies"] != null)
        //    {
        //        if (Request.Cookies["IPortalCookies"]["Likes"] == null || Request.Cookies["IPortalCookies"]["Likes"].Contains("'" + articleid + "'") == false)
        //        {
        //            if (_ah.LikeIt(articleid))
        //            {
        //                Response.Cookies["IPortalCookies"]["Likes"] = Request.Cookies["IPortalCookies"]["Likes"] + ",'" + articleid + "'";
        //                BindRepeater();
        //            }
        //        }
        //    }
但是,当喜欢的cookie创建时,其他cookie将消失,我将得到以下错误:

String reference not set to an instance of a String.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: name

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentNullException: String reference not set to an instance of a String.
Parameter name: name]
   System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) +14174389
   PortalCore.Global.Application_BeginRequest(Object sender, EventArgs e) +1093
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

我不知道哪一行抛出了这个错误

但是我可以把下面这行搞错吗

if (Request.Cookies["IPortalCookies"]["Likes"] == null || Request.Cookies["IPortalCookies"]["Likes"].Contains("'" + articleid + "'") == false)
        //        {
        //            if (_ah.LikeIt(articleid))
        //            {
        //                Response.Cookies["IPortalCookies"]["Likes"] = Request.Cookies["IPortalCookies"]["Likes"] + ",'" + articleid + "'";
        //                BindRepeater();
        //            }
        //        }
您需要检查not equal null

Request.Cookies["IPortalCookies"]["Likes"] != null
在尝试获取cookie的值之前,您应该确保cookie存在;如果cookie不存在,您将得到一个NullReferenceException异常


哪一行抛出了这个错误?比如说,我编写了一个接受模块的门户,在我正在创建模块的项目中,它工作正常,但当我加载localhost(核心门户)时,它显示了这个错误。(事实上,我有两个项目,一个在visual studio中,另一个在localhost文件夹中)