代码改变世界

检测到有潜在危险的 Request.Form 值。

2013-02-05 11:09 by Carl Xing, 141 阅读, 0 推荐, 收藏, 编辑
摘要:页面中使用编辑器时会检测到有潜在危险的 Request.Form 值。2种解决办法:1、在提交表单前escape要提交的值,在读取值时unescape2、在使用编辑器的页面<%@ Page里加上ValidateRequest="false",如果使4.0系统,需要在web.config里的system.web节点下添加 <httpRuntime requestValidationMode="2.0"/> 如果使用mvc在MVC的 方法 或控制器上 加入 [ValidateInput(false)]标识。 阅读全文

自定义配置节点

2013-01-10 18:04 by Carl Xing, 177 阅读, 0 推荐, 收藏, 编辑
摘要:创建工程,添加文件:Program调用,ConfigSection用于配置,Configs为节点集合,Config为实际应用节点。App.Config:<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="ConfigSection" type="ConfigurationTest.ConfigSection,ConfigurationTest"/> 阅读全文

创建、停止、删除 windows服务

2013-01-08 17:34 by Carl Xing, 286 阅读, 0 推荐, 收藏, 编辑
摘要:cmd console中,或保存成bat文件执行sc create 服务名称 binpath= 执行文件路径 type= own start= auto displayname= 服务展示名称=后面要有空格net stop服务名称sc delete服务名称 阅读全文

SqlBulkCopy的使用

2012-11-22 17:12 by Carl Xing, 242 阅读, 0 推荐, 收藏, 编辑
摘要:将datatable 中的表写入一张临时表。注意:临时表只存在与一个连接中,只有当前连接可以操作临时表,当连接关闭,临时表消失。 DataTable dt = new DataTable(); dt.Columns.Add("col", typeof(int)); for (int i = 10000; i < 100000; i++) { dt.Rows.Add(new object[] { i }); } string connS... 阅读全文

为VisualStudio默认模板添加版权信息

2012-08-13 14:56 by Carl Xing, 285 阅读, 0 推荐, 收藏, 编辑
摘要:类及接口模板自定义:文件夹下打开code.zip , interface.zipvs2010在Microsoft Visual Studio 10……文件夹下双击打开压缩包,不要解压。然后双击模板文件, IDE会自动启动打开文件/*----------------------------------------------------------------------------------- * 版权所有:xxx科技有限责任公司 * 作者:xxx * 联系方式:xxx * 创建时间:$time$ * 版本号:V1.0 * 本类主要用途描述: ------------------------ 阅读全文

邮件发送

2012-07-17 17:59 by Carl Xing, 207 阅读, 0 推荐, 收藏, 编辑
摘要:前台界面:后台代码:(不同的邮件主机可能会需要端口号)using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net.Mail;using System.Net;using System.Threading;namespace Mail{ public partial c... 阅读全文

Socket

2012-07-10 16:55 by Carl Xing, 347 阅读, 0 推荐, 收藏, 编辑
摘要:1、基于TCP的web服务器 windows控制台应用程序class Program { static void Main(string[] args) { //SocketServer(); GetClientMsg(... 阅读全文

文件下载

2012-05-04 12:23 by Carl Xing, 186 阅读, 0 推荐, 收藏, 编辑
摘要:protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (FileStream fs = new FileStream(Server.MapPath("~/123.txt"), FileMode.OpenOrCreate)) { int streamLength = (int)fs.Length; ... 阅读全文

缓存依赖

2012-05-02 16:48 by Carl Xing, 233 阅读, 0 推荐, 收藏, 编辑
摘要:public List<MenuEntity> GetMenus() { List<MenuEntity> menuList = null; SqlCacheDependency sqlDep; if (HttpContext.Current.Cache["menu"] == null) { menuList = new List<MenuEntity>(); using (SqlConnection conn = ne... 阅读全文

WIA的使用及自定义可拖拽大小的picturebox

2012-02-08 15:17 by Carl Xing, 753 阅读, 0 推荐, 收藏, 编辑
摘要:首先看工程的结构,主要包括主界面,自定义控件和webservice的引用。需要引用com组建,win7中自带wia2.0,其它系统若不带可注册,注册方法从微软官网下载的wia2.0组建包中有说明。工程采用clickonce发布:自定义控件UCPicturebox的界面为下图,由一个picturebox和四个label组成。后台代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;us 阅读全文