多么期待那2012的到来,迎接那光子带的世界……

.NET Framework 4.0的新特性

 本文将揭示.NET 4.0中的3个新特性:图表控件、SEO支持以及ASP.NET 4可扩展的输出缓存。

图表控件
微软向开发者提供了大量可免费下载的图表控件,可以在.NET 3.5 ASP.NET或WinForms项目中使用这些控件。要想在Visual Studio 2008中使用这些控件则需要安装一个插件,该插件提供了VS工具箱及智能集成功能。现在这些控件已经集成到了.NET 4.0中,这样就无需再去下载额外的插件了。Samples Environment for MS Chart Controls提供了这些控件的使用示例。下图是示例的运行截图:
...

.net windows服务程序编写总结

1、在.net中,windows服务的实现类必需继承于System.ServiceProcess.ServiceBase
public partial class myService : ServiceBase
{
 
}
2、在windows服务的实现类的构造函数中进行必要的初始化工作,如设置系统标识服务的简短名称等。
public partial class myService : ServiceBase
...

.net实例:C#创建Windows服务

Windows服务在Visual Studio 以前的版本中叫NT服务,在VS.net启用了新的名称。用Visual C# 创建Windows服务不是一件困难的事,本文就将指导你一步一步创建一个Windows服务并使用它。这个服务在启动和停止时,向一个文本文件中写入一些文字信息。

 

第一步:创建服务框架
要创建一个新的 Windows 服务,可以从Visual C# 工程中选取 Windows 服务(Windows Service)选项,给工程一个新文件名,然后点击 确定。

...

DbType,OleDbType,SqlDbType区别

 

_DbType,OleDbType,SqlDbType区别 - 上古神话 - 我的博客 _

...

网页信息采集 核心代码收集

 

  1. 1.通过HttpWebResponse 来获取 
  2. public static string CheckTeamSiteUrl(string url)   
  3.     {   
  4.         string response = "";   
  5.         HttpWebResponse httpResponse = null;   
  6.    
  7.         //assert: user have access to URL    
  8.         try   
  9.         {   
  10.             HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);   
  11.             httpRequest.Headers.Set("Pragma""no-cache");   
  12.    
  13.                 // request.Headers.Set("KeepAlive", "true");   
  14.    
  15.                 httpRequest.CookieContainer = new CookieContainer();   
  16.    
  17.    
  18.    
  19.                 httpRequest.Referer = url;   
  20.    
  21.                 httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";   
  22.    
  23.                  
  24.    
  25.             httpRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;   
  26.             httpResponse = (HttpWebResponse)httpRequest.GetResponse();   
  27.                
  28.         }   
  29.         catch (Exception ex)   
  30.         {   
  31.             throw new ApplicationException("HTTP 403 Access denied, URL: " + url, ex);   
  32.         }   
  33.    
  34.         //if here, the URL is correct and the user has access    
  35.         try   
  36.         {   
  37.             string strEncod = httpResponse.ContentType;   
  38.             StreamReader stream;   
  39.             if (strEncod.ToLower().IndexOf("utf") != -1)   
  40.             {   
  41.                 stream = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8);   
  42.             }   
  43.             else   
  44.             {   
  45.                 stream = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.Default);   
  46.             }   
  47.               
  48.             char[] buff = new char[4000];   
  49.             stream.ReadBlock(buff,0,4000);   
  50.             response = new string(buff);   
  51.             stream.Close();   
  52.             httpResponse.Close();   
  53.         }   
  54.         catch (Exception ex)   
  55.         {   
  56.             throw new ApplicationException("HTTP 404 Page not found, URL: " + url, ex);   
  57.         }   
  58.         return response;   
  59.    
  60.     }   
  61.   
  62.  
  63. 2.通过 WebResponse 来获取 
  64.  public static string getPage(String url)   
  65.     {   
  66.         WebResponse result = null;   
  67.         string resultstring = "";   
  68.         try   
  69.         {   
  70.             WebRequest req = WebRequest.Create(url);   
  71.             req.Timeout = 30000;   
  72.             result = req.GetResponse();   
  73.             Stream ReceiveStream = result.GetResponseStream();   
  74.    
  75.             //read the stream into a string   
  76.             //StreamReader sr = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);   
  77.             string strEncod = result.ContentType;   
  78.             StreamReader sr;   
  79.             if (strEncod.ToLower().IndexOf("utf") != -1)   
  80.             {   
  81.                 sr = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);   
  82.             }   
  83.             else   
  84.             {   
  85.                 sr = new StreamReader(ReceiveStream, System.Text.Encoding.Default);   
  86.             }   
  87.             resultstring = sr.ReadToEnd();   
  88.             js.alert(resultstring);   
  89.             //Console.WriteLine(resultstring);   
  90.         }   
  91.         catch   
  92.         {   
  93.             throw new Exception();   
  94.         }   
  95.         finally   
  96.         {   
  97.             if (result != null)   
  98.             {   
  99.                 result.Close();   
  100.             }   
  101.         }   
  102.         return resultstring;   
  103.     }   
  104.   
  105.  
  106. 3.通过WebClient来获取 
  107.  public string get(int length)   
  108.     {   
  109.         try   
  110.         {   
  111.             getEncodeing();   
  112.             WebClient wb = new WebClient();   
  113.             Stream response = wb.OpenRead(url);   
  114.             StreamReader reader = new StreamReader(response, this.encoding, true, 256000);   
  115.             char[] a = new char[length];   
  116.             int i  = reader.Read(a,0,length);   
  117.             reader.Close();   
  118.             return new string(a);   
  119.         }   
  120.         catch (Exception e)   
  121.         {   
  122.             return e.Message;   
  123.             //return null;   
  124.         }   
  125.     }   
  126.     private void getEncodeing()   
  127.     {   
  128.         switch (this.encode)   
  129.         {   
  130.             case "UTF-8": encoding = Encoding.UTF8; break;   
  131.             case "GB2312": encoding = Encoding.GetEncoding("GB2312"); break;   
  132.             case "ASCII": encoding = Encoding.ASCII; break;   
  133.             default: encoding = Encoding.GetEncoding(encode); break;   
  134.         }   
  135.     }   
...

.net连接MYSQL字符串

<add key="MySqlString" value="server=localhost;port=3306;user id=userid;password=123456;database=dbname;CharSet=utf8;Allow Zero Datetime=true"/>

ScriptManager.RegisterStartupScript失效的解决方案

今天在项目中一个页面使用 System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "js", "alert('OK');", true);的时候发现没用,检查发现脚本没用注册到页面, check页面发现了问题,<form method="post">

VS2010安装项目的系统必备中添加.NET 2.0

  VS2010安装项目的系统必备中没有.NET 2.0,不过我们可以从VS2008的程序文件中找到 .NET 2.0 的系统必备安装包。

    安装了VS2008 的 C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages 下的 DotNetFX 文件夹,就是 .NET 2.0 的系统必备安装包。把 DotNetFX 文件夹复制到安装了 VS2010 的 C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages下,然后在VS2010中就可以选择 .NET 2.0 的系统必备了。

...

asp.net的checkboxlist绑定数据

1.把数据绑定到CheckBoxList中

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = GetDBCon.GetCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from admin", con);
...

关于session超时问题

       接管负责了公司的一个项目网站后台管理,客服部要求会话间隔时间能长点,于是在web.config里改了outtime设置,设成了8个小时,一个工作日的时间,可是修改后居然不起作用,依旧是20分钟不操作就得重登录。于是把服务器上的IIS超时设置也改了,会话超时设置成480分钟,但是问题仍然存在(关于outtime的设置,一般web.config的优先级别高于machine.config高于IIS设置。)。仔细查看了代码,是用session保存信息而不是cookie,代码中没有有关超时的设置了。搞了半天问题才解决。

...
分页:«123»

Copyright 光子时代 Rights Reserved.

Powered By Z-Blog 1.8 Walle Build 91204

RSS feeds