2008年6月小记

1、SP拆分字符串,如把a1,a2,a3以,分隔拆分出来
ALTER   PROCEDURE   [ dbo ] . [ ec_System_SplitString ]
    
@strs   nvarchar ( 4000 ),
    
@separator   nchar ( 1 ) = ' , '
AS
BEGIN
    
SET  NOCOUNT  ON ;

    
DECLARE   @tbNames      table ( [ Name ]   nvarchar ( 256 NOT   NULL   PRIMARY   KEY )
    
DECLARE   @Num          int ;
    
DECLARE   @Pos          int ;
    
DECLARE   @NextPos      int ;
    
DECLARE   @Name          nvarchar ( 256 );
    
SET   @Num   =   0 ;
    
SET   @Pos   =   1 ;

    
WHILE ( @Pos   <=   LEN ( @strs ))
    
BEGIN
        
SELECT   @NextPos   =   CHARINDEX ( @separator @strs ,   @Pos )
        
IF  ( @NextPos   =   0   OR   @NextPos   IS   NULL )
            
SELECT   @NextPos   =   LEN ( @strs +   1
        
SELECT   @Name   =   RTRIM ( LTRIM ( SUBSTRING ( @strs @Pos @NextPos   -   @Pos )))
        
SELECT   @Pos   =   @NextPos + 1

        
        
INSERT   INTO   @tbNames   VALUES  ( @Name )
        
SET   @Num   =   @Num   +   1
    
END

    
SELECT   [ Name ]   FROM   @tbNames

END

2、在IIS7中如何继续使用 URLRewriterApplicationErrorLog
<system.web>中配置也要在 <system.webServer>中添加一份
如有如下的配置
< system.web >
    
< httpModules >
        
< add type = " URLRewriter.ModuleRewriter, URLRewriter "  name = " ModuleRewriter " />
    
</ httpModules >
</ system.web >
同时也应该在 <system.webServer>中添加一份
< system.webServer >
    
< modules >
        
< add type = " URLRewriter.ModuleRewriter, URLRewriter "  name = " ModuleRewriter " />
    
</ modules >
</ system.webServer >
ApplicationErrorLog配置
< system.web >
    
< httpHandlers >
        
< add  verb ="POST,GET,HEAD"  path ="ErrorLog.aspx"  type ="Lion.Web.ApplicationErrorLog.ErrorLogPageFactory, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    
</ httpHandlers >
    
< httpModules >
        
< add  name ="ErrorLog"  type ="Lion.Web.ApplicationErrorLog.ErrorLogModule, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    
</ httpModules >
</ system.web >
< system.webServer >
    
< handlers >
        
< add  name ="ApplicationErrorLog"  verb ="POST,GET,HEAD"  path ="ErrorLog.aspx"  type ="Lion.Web.ApplicationErrorLog.ErrorLogPageFactory, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    
</ handlers >
    
< modules >
        
< add  name ="ErrorLog"  type ="Lion.Web.ApplicationErrorLog.ErrorLogModule, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    
</ modules >
</ system.webServer >

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

4、通过子类构建父类
public   class  RecordHistory : RecordMetadata

         private  RecordHistory CopyToRecordHistory(RecordMetadata metadata)
        
{
            
//使用反射把RecordMetadata导入到RecordHistory
            RecordHistory history = null;

            
if (metadata != null)
            
{
                history 
= new RecordHistory();

                Type historyType 
= history.GetType();
                Type metadataType 
= metadata.GetType();

                PropertyInfo[] historyProperties 
= historyType.GetProperties();
                
foreach (PropertyInfo historyProperty in historyProperties)
                
{
                    PropertyInfo metadataProperty 
= metadataType.GetProperty(historyProperty.Name);
                    
if (metadataProperty != null)
                    
{
                        metadataProperty.SetValue(history, metadataProperty.GetValue(metadata, 
null), null);
                    }

                }

            }


            
return history;
        }

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所致,所以定义可以改为
        [Column(Name  =   " Audit " , DbType  =   " tinyint " )]
        
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());

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);



10、将访问Windows文件夹变为磁盘盘符

11、通过FileIOPermission进行代码访问权限检测

FileIOPermission permission  =   new  FileIOPermission(FileIOPermissionAccess.Read, @" c:\billchen.txt " );
permission.Demand();

12、使用 StringComparer创建大小写无关的字典:
Dictionary < string int >  dic  =   new  Dictionary < string int > (StringComparer.InvariantCultureIgnoreCase);
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




转载于:https://www.cnblogs.com/BillChen/archive/2008/06/16/1222859.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值