• 主体思路就是,直接修改cookie.expires,然后再添加Response.Cookies.Add,如果设置为负数,就是将其删除。

    或者在同一个域,再新建一个同名的cookie,添加到cookie中,也就把原有的cookie替换了,修改和删除都是这样的思路,只不过删除就是将失效时间置为小于当前时间。

    总结:内存cookie就是不用设置expires,cookie存于内存中,关闭浏览器或退出cookie即失效。

            硬盘cookie,就是设置expires大于当前时间,便会生成cookie文件,修改为小于等于当前时间后,cookie失效,文件被删除,如果不修改,时间到了后会失效,文件依然存在。

    以上总结为实验所得结果,不对之处欢迎拍砖,另外.net里还有个方法HttpContext.Current.Response.Cookies.Remove(“cookiename”);,但是我实验了一下,没发现是删除什么的。

  • 方法一:如果想把数据库A中的表Table1中的数据复制到数据库B中的表Table2中,也就是要预先建立Table2,可以使用一下语句:

    use B

    go
    insert into Table2 select [字段] from A..Table1
    go

    注意:

    1、A后面是两个点。

    2、select的字段一般不能包括自增ID字段。

    &...
  • Code Snippet
    1. using System;
    2. using System.Web.UI;
    3. using System.Web.UI.WebControls;
    4. using System.ComponentModel;
    5.  
    6. namespace Common
    7. {
    8.  
    9.     // Attribute DefaultProperty指定组件的默认属性,ToolboxData指定当从IDE工具中的
    10.  
    11.     //工具箱中拖动自定义控件时为它生成的默认标记
    12.  
    13.     [DefaultProperty("Text"),
    14.  
    15.     ToolboxData("<{0}:MyControl runat=server>")]
    16.  
    17.     //类MyControl派生自WebControl
    18.  
    19.     public class MyControl : System.Web.UI.WebControls.WebControl
    20.     {
    21.  
    22.         private string text;
    23.  
    24.         //Attribute Bindable指定属性是否通常用于绑定
    25.  
    26.         //Category指定属性或事件将显示在可视化设计器中的类别
    27.  
    28.         //DefalutValue用于指定属性的默认值
    29.  
    30.         [Bindable(true),
    31.  
    32.         Category("Appearance"),
    33.  
    34.         DefaultValue("")]
    35.  
    36.         public string Text
    37.         {
    38.  
    39.             get
    40.             {
    41.  
    42.                 return text;
    43.  
    44.             }
    45.  
    46.             set
    47.             {
    48.  
    49.                 text = value;
    50.  
    51.             }
    52.  
    53.         }
    54.  
    55.         //重写WebControl的Render方法,采用HtmlTextWriter类型的参数
    56.  
    57.         protected override void Render(HtmlTextWriter output)
    58.         {
    59.  
    60.             //发送属性Text的值到浏览器
    61.  
    62.             output.Write("" + "Text" + "");//最后页面显示的是Text。
    63.  
    64.  
    65.         }
    66.  
    67.     }
    68.  
    69. }

    1、控件可分为.net framework提供的控件、用户控件(User control)、自定义控件(Custom control).

    2、用户控件文件类型为.ascx.自定义控件文件类型为类库文件.cs,且一定要继承自System.Web.UI.WebControls.WebControl

    3、用户控件可以直接拖拽到aspx文件中使用,自定义控件需要编译成dll文件被引用。

    4、要在引用中添加dll文件,在cs文件中using命名空间,在aspx文件中注册自定义控件例如:

    或者是在web.config中的里添加

    然后就可以在aspx页面添加控件,此时工具箱中应该也会有控件,可以自己拖拽到aspx页面中,也可以添加代码如下:

     

  • Code Snippet
    1. using System;
    2. using System.Net;
    3. using System.Net.Mail;
    4. using System.Net.NetworkInformation;
    5. using System.Text;
    6. using System.Threading;
    7. using System.Windows.Forms;
    8.  
    9. namespace ConsoleApplication2
    10. {
    11.     public class PingExample
    12.     {
    13.         public static void Main()
    14.         {
    15.             SendMailUseGmail();
    16.         }
    17.  
    18.         public static void SendMailUseGmail()
    19. {
    20. MailMessage msg = new MailMessage();
    21. msg.To.Add("邮箱地址");
    22. /*
    23. * msg.To.Add("b@b.com");
    24. * msg.To.Add("b@b.com");
    25. * msg.To.Add("b@b.com");可以发送给多人
    26. */
    27. //msg.CC.Add("c@c.com");
    28. /*
    29. * msg.CC.Add("c@c.com");
    30. * msg.CC.Add("c@c.com");可以抄送给多人
    31. */
    32. msg.From = new MailAddress("户名@gmail.com""姓名"Encoding.UTF8);
    33. /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
    34. msg.Subject = "这是测试邮件";//邮件标题
    35. msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
    36. msg.Body = "邮件内容";//邮件内容
    37. msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
    38. msg.IsBodyHtml = false;//是否是HTML邮件
    39. msg.Priority = MailPriority.High;//邮件优先级
    40. SmtpClient client = new SmtpClient();
    41. client.Credentials = new NetworkCredential("账户名@gmail.com""密码");
    42. //上述写你的GMail邮箱和密码
    43. client.Port = 587;//Gmail使用的端口
    44. client.Host = "smtp.gmail.com";
    45. client.EnableSsl = true;//经过ssl加密
    46. try
    47. {
    48. client.Send(msg);
    49. //简单一点儿可以client.Send(msg);
    50. MessageBox.Show("发送成功");
    51. }
    52. catch (SmtpException ex)
    53. {
    54. MessageBox.Show(ex.Message, "发送邮件出错");
    55. }
    56. }
    57.     }
    58. }

     

  • 以上两篇文章已经很丰富了,但是照做一遍不行,检查了N遍还是不行,就是找不出问题原因,总是提示“尚未为数据源“DataSet1_DataTable1”提供数据源实例。”这主要是说在为ReportViewer控件选择数据源的时候,还没有选择数据源实例,如图所示,...

  • Sample Image - maximum width is 600 pixels

    这篇文章图比较多,更方便学习,但这里还是少了几个截图,同样为了拿来说事先转载一下。

  • 已经无法考证这篇文章的原创是出自哪里了,网上可以搜出很多引用,为了拿来说事我先转载一下,但我还是注一下出处http://blog.csdn.net/wujilin/archive/2009/05/11/4167821.aspx

  • Code Snippet
    1. using System;
    2. using System.Data;
    3. using System.Data.OleDb;
    4. using System.Net;
    5. class TestADO
    6. {
    7.     static void Main()
    8.     {
    9.         IPHostEntry ips =Dns.GetHostEntry(Dns.GetHostName());
    10.         int i = 0;
    11.         foreach (IPAddress ip in ips.AddressList)
    12.         {
    13.             if(i==2)
    14.             Console.WriteLine(ip.ToString());
    15.             i++;
    16.         }
    17.         Console.ReadKey(true);
    18.     }
    19. }
  • 2010-11-06

    C#读取表的属性 - [IT]

    Tag: C# 属性

     

    Code Snippet
    1. using System;
    2. using System.Data;
    3. using System.Data.OleDb;
    4. class TestADO
    5. {
    6.     static void Main(string[] args)
    7.     {
    8.         string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\test.mdb";
    9.         string strSQL ="SELECT * FROM employees" ;
    10.         OleDbConnection conn = new OleDbConnection(strDSN);
    11.         OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn );
    12.         conn.Open();
    13.         DataSet ds = new DataSet();
    14.         cmd.Fill( ds, "employees" );
    15.         DataTable dt = ds.Tables[0];
    16.         Console.WriteLine("Field Name DataType Unique AutoIncrement AllowNull");
    17.         Console.WriteLine("==================================================================");
    18.         foreach( DataColumn dc in dt.Columns )
    19.         {
    20.             Console.WriteLine(dc.ColumnName+" ," +dc.DataType +","+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
    21.         }
    22.         Console.ReadKey(true);
    23.         conn.Close();
    24.     }
    25. }

     

  •  

    Code Snippet
    1. using System;
    2. using System.Data;
    3. using System.Data.OleDb;
    4. class TestADO
    5. {
    6.     static void Main(string[] args)
    7.     {
    8.         string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb";
    9.         string strSQL = "SELECT * FROM employees ";
    10.         OleDbConnection conn = new OleDbConnection(strDSN);
    11.         OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn );
    12.         conn.Open();
    13.         DataSet ds = new DataSet();
    14.         cmd.Fill( ds, "employees");
    15.         DataTable dt = ds.Tables[0];
    16.         foreach( DataRow dr in dt.Rows )
    17.         {
    18.             Console.WriteLine("First name: "+ dr["FirstName"].ToString() +" Last name: "+ dr["LastName"].ToString());
    19.         }
    20.         Console.ReadKey(true);
    21.         conn.Close();
    22.     }
    23. }

     

  •  

    Code Snippet
    1. using System;
    2. using System.Data;   
    3. using System.Data.OleDb;  
    4. class TestADO
    5. {
    6.     static void Main(string[] args)
    7. {
    8.         string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb";
    9.         string strSQL = "INSERT INTO employees (FirstName, LastName) VALUES('Li', 'Gang')" ;
    10.                    
    11.         // create Objects of ADOConnection and ADOCommand   
    12.         OleDbConnection conn = new OleDbConnection(strDSN);
    13.         OleDbCommand cmd = new OleDbCommand( strSQL, conn );
    14.         try
    15.         {
    16.             conn.Open();
    17.             cmd.ExecuteNonQuery();
    18.         }
    19.         catch (Exception e)
    20.         {
    21.             Console.WriteLine("Oooops. I did it again: {0}", e.Message);
    22.             Console.ReadKey(true);
    23.         }
    24.         finally
    25.         {
    26.             conn.Close();
    27.         }          
    28.     }
    29. }

     

  •  

    Code Snippet
    1. using System;
    2. using System.Data;
    3. using System.Xml;
    4. using System.Data.SqlClient;
    5. using System.IO;
    6. public class TestWriteXML
    7. {
    8.     public static void Main()
    9.     {
    10.         String strFileName="d:\\test\\output.xml";
    11.         SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=zl@sxadc;database=y213");
    12.         String strSql = "SELECT * FROM UserLogin";
    13.         SqlDataAdapter adapter = new SqlDataAdapter();
    14.         adapter.SelectCommand = new SqlCommand(strSql,conn);
    15.         // Build the DataSet
    16.         DataSet ds = new DataSet();
    17.         adapter.Fill(ds, "UserLogin");
    18.         // Get a FileStream object
    19.         FileStream fs = new FileStream(strFileName,FileMode.OpenOrCreate,FileAccess.Write);
    20.         // Apply the WriteXml method to write an XML document
    21.         ds.WriteXml(fs);
    22.         fs.Close();
    23.     }
    24. }

     

  •  

    Code Snippet
    1. using System;
    2. using System.Data.SqlClient;
    3. public class TestADO
    4. {
    5.     public static void Main()
    6.     {
    7.         SqlConnection conn = new SqlConnection("Data Source=localhost;User ID=sa;Password=sa;Database=y213;");
    8.         SqlCommand cmd = new SqlCommand("SELECT * FROM UserLogin", conn);
    9.         try
    10.         {        
    11.             conn.Open();
    12.             SqlDataReader reader = cmd.ExecuteReader();            
    13.             while (reader.Read())
    14.             {
    15.                 Console.WriteLine("ID:{0},First Name: {1}, Last Name: {2}", reader.GetInt32(0),reader.GetString(1), reader.GetString(2));
    16.             }
    17.             Console.ReadKey(true);
    18.             reader.Close();
    19.             conn.Close();
    20.         }
    21.         catch(Exception e)
    22.         {
    23.             Console.WriteLine("Exception Occured -->> {0}",e);
    24.         }        
    25.     }
    26. }

     

  • Code Snippet
    1. using System;
    2. using System.Data;
    3. using System.Data.OleDb;
    4. class TestADO
    5. {
    6.     static void Main(string[] args)
    7.     {
    8.         string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb";
    9.         string strSQL = "SELECT * FROM employees ";
    10.         OleDbConnection conn = new OleDbConnection(strDSN);
    11.         OleDbCommand cmd = new OleDbCommand( strSQL, conn );
    12.         OleDbDataReader reader = null;
    13.         try
    14.         {
    15.             conn.Open();
    16.             reader = cmd.ExecuteReader();
    17.             while (reader.Read() )
    18.             {
    19.                 Console.WriteLine("First Name:{0}, Last Name:{1}", reader["FirstName"], reader["LastName"]);
    20.             }
    21.             Console.ReadKey(true);
    22.         }
    23.         catch (Exception e)
    24.         {
    25.             Console.WriteLine(e.Message);
    26.         }
    27.         finally
    28.         {
    29.             conn.Close();
    30.         }
    31.     }
    32. }

     

  • 2010-11-05

    Copy As HTML - [IT]

    Tag: vs 插件

    Lavernock Enterprises Copy As HTML

  • Code Snippet
    1. using System;
    2. using System.Timers;
    3.  
    4. namespace ConsoleApplication2
    5. {
    6.     class Program
    7.     {
    8.         static void Main(string[] args)
    9.     {
    10.         Timer timer = new Timer();
    11.         timer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
    12.         timer.Interval = 1000;
    13.         timer.Start();
    14.         timer.Enabled = true;
    15.         while (true)
    16.         {
    17.             Test();
    18.         }     
    19.     }
    20.     public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
    21.     {
    22.         Console.Write("{0} ", DateTime.Now);
    23.     }
    24.     static void Test()
    25.     {
    26.         ConsoleKeyInfo keyinfo = Console.ReadKey(true);
    27.         if (keyinfo.KeyChar.ToString()=="q")
    28.         {
    29.             Environment.Exit(0);
    30.         }
    31.     }
    32.     }
    33. }
  • Moves a specified file to a new location, providing the option to specify a new file name.

    完整代码如下:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.IO;

     

    namespace ConsoleApplic...
  • 2010-11-04

    BaseStream.seek - [IT]

    Tag: seek 文件 IO
    我对文本进行读操作! 
    问题: 
    StreamReader   sr   =   new   StreamReader(fs) 
    //定位于文本的开始   偏移量 
    sr.BaseStream.seek(0,SeekOrigin.Begin) 
    疑问: 
    seek   中的“0”是偏移...

  • 注意:aspx内有个关键字是Inherits="JuSNS.Web.Default"    而在aspx.cs中也有个关键字public partial
    class Default
    这两个关键字已经告诉了我们两个文件的关系既:aspx.cs中的分部类其中一部门是他本身,另一部门有aspx里面的内容生成,而aspx的...
  • 使用命令行工具SDK Command Prompt,键入:SN -T C:\*****.dll

    就会显示出该dll具体的PublicKeyToken数值。

    如果该程序集没有强命名,则不会有PublicKeyToken数值。

    将一个程序集强命名的方法是:

    用SN -k C:\***.snk命令生成***.snk文件,将该snk文件加载到项目...