/// <summary>
        /// 写cookie值
        /// </summary>
        /// <param name="strName">名称</param>
        /// <param name="strValue">值</param>
        /// <param name="strValue">过期时间(分钟)</param>
        public static void WriteCookie(string strName, string strValue, int expires, bool cookieHttpOnly)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
            if (cookie == null)
            {
                cookie = new HttpCookie(strName);
            }
            cookie.Value = strValue;
            cookie.Expires = DateTime.Now.AddMinutes(expires);
            cookie.HttpOnly = cookieHttpOnly;
            
            HttpContext.Current.Response.AppendCookie(cookie);
        /// <summary>
        /// 读cookie值
        /// </summary>
        /// <param name="strName">名称</param>
        /// <returns>cookie值</returns>
        public static string GetCookie(string strName)
        {
            
            if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
            {
                return HttpContext.Current.Request.Cookies[strName].Value.ToString();
            }            return "";
        }        /// <summary>
        /// 删除指定名称cookie
        /// </summary>
        /// <param name="cookiename"></param>
        public static void DelCookie(string cookiename)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiename];
            cookie.Expires = DateTime.Now.AddMinutes(-1);
            HttpContext.Current.Response.AppendCookie(cookie);
        }登陆时调用
            Cookie.WriteCookie("id", x1,30, true);//id,cookies用于javascript不能读取的
            Cookie.WriteCookie("name", x2,30, false);//javascript能读取的
判断身份时
if (MyCookie.GetCookie("id")) ==0) 则...  出现以下错误(本要都正常,上传则出现以下错误)我的网站用了三个域,其中二个为二级域,都是用重写实现的,是因为这个原因吗?
Server Error in '/' Application.
--------------------------------------------------------------------------------Input string was not in a correct format. 
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.FormatException: Input string was not in a correct format.Source Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example:  <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  Stack Trace: 
[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7467367
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Convert.ToInt32(String value) +63
   MyApp.Web.UI.V..ctor() in E:\Mydll\MyApp.Web.UI\V.cs:20
.....
 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053  

解决方案 »

  1.   

    debug一下呀 估计是没判断cookies为null的情况导致的。
      

  2.   

    MyCookie.GetCookie("id")的值为空,你让它和0比较,它就会强制转化成数字,而空字串怎么能变成数字那,所以出错了。 改成:if (!String.IsEmptyOrNull(MyCookie.GetCookie("id")))) 
    {
       if (MyCookie.GetCookie("id")) ==0) 
       {
         .....
      }
    }
      

  3.   

    输入字符串格式化错误if (!String.IsEmptyOrNull(MyCookie.GetCookie("id")))
    {
      if (MyCookie.GetCookie("id").Equals("0")) 
      {
         
      }  
    }
      

  4.   

    本机调试没问题呀,cookie到服务器就不好用,是怎么回事呢?
      

  5.   

    Exception Details: System.FormatException: Input string was not in a correct format. 看明白是什么错误,就能解决问题了。
      

  6.   

    问题解决了wuyq11
     
    (人生如梦) 正解