






























2、在IIS7中如何继续使用URLRewriter及ApplicationErrorLog
在<system.web>中配置也要在<system.webServer>中添加一份
如有如下的配置


























3、去除IIS7的30MB上传限制
修改文件C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml
<attribute name="maxAllowedContentLength" type="uint" defaultValue="30000000" />
加个0就是300MB
4、通过子类构建父类


























5、Linq to SQL中如何解决"Specified cast is not valid"的问题
在使用Linq to SQL中对象属性与数据库中表字段的类型转换无效的问题 ,例如:数据表字段Audit的类型为tinyint,它对应的对象是
[Column(Name = "Audit")]
public Int16 Audit { get; set; }
但是这样在query时会出现"Specified cast is not valid"的错误,其实这是在定义DataContext对象时没有指定DbType所致,所以定义可以改为public Int16 Audit { get; set; }
[Column(Name = "Audit", DbType = "tinyint")]
public Int16 Audit { get; set; }
public Int16 Audit { get; set; }
6、 异步调用asmx的Web方法
引用asmx页面,VS会自动生成代理,除了原生的方法外例如PingPost,还会自动生PingPostAsync这样以Async尾的相对应异常调用方法,不过使用这个异步方法的页面还是需要设置一下
<%@ Page Async="true" %>
7、SQL常用语句收集
8、判断一个js对象是否未定义:if(typeof(kk) == 'undefined')
9、使用UriBuilder移除url参数
Response.Output.Write(new UriBuilder(Request.Url)
{
Query=null
}.ToString());
{
Query=null
}.ToString());
http://localhost:46630/CSDN.ExpertCenter.WebTest/Demos/B.aspx?username=billok&count=12 ==>
http://localhost:46630/CSDN.ExpertCenter.WebTest/Demos/B.aspx
通过扩展UriBuilder类来增强功能的类还有UrlBuilder
另外:VirtualPathUtility 类为涉及虚拟路径的常见操作提供实用工具方法。
VirtualPathUtility.IsAppRelative 判断是否为虚拟路径.
HttpRuntime 和 HostingEnvironment 都是很实用的辅助工具。
Path.IsPathRooted 判断是不是为绝对路径
if (!Path.IsPathRooted(path))
path = HttpContext.Current.Server.MapPath(path);
path = HttpContext.Current.Server.MapPath(path);
10、将访问Windows文件夹变为磁盘盘符
11、通过FileIOPermission进行代码访问权限检测
FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read,@"c:\billchen.txt");
permission.Demand();
permission.Demand();
12、使用StringComparer创建大小写无关的字典:
Dictionary<string, int> dic = new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);
dic["Test"] = 10;
int n = dic["test"];
dic["Test"] = 10;
int n = dic["test"];
13、排重表的重复行
select a.username,a.tagname,a.tagtype into temp
from usertags a
group by a.username,a.tagname,a.tagtype
truncate table UserTags
insert into UserTags(username,tagname,tagtype)
select username,tagname,tagtype
from temp
drop table temp
from usertags a
group by a.username,a.tagname,a.tagtype
truncate table UserTags
insert into UserTags(username,tagname,tagtype)
select username,tagname,tagtype
from temp
drop table temp