2009年6月小记(group by统计合并,js关闭本窗口,wcf捕捉错误,便宜的域名解析方法,当前外网IP)
1、group by统计合并
select [UserName],
sum([上传图片]) as [上传图片],
sum([添加分享]) as [添加分享],
sum([上传图片]+[添加分享]) as '总数'
from @tb
group by [UserName]
order by sum([上传图片]+[添加分享]) desc
sum([上传图片]) as [上传图片],
sum([添加分享]) as [添加分享],
sum([上传图片]+[添加分享]) as '总数'
from @tb
group by [UserName]
order by sum([上传图片]+[添加分享]) desc
2、js关闭本窗口
<script type="text/javascript">
function closeit() {
top.window.opener = top;
top.window.open('', '_self', '');
top.window.close();
}
setTimeout('closeit()', 3000);
</script>
function closeit() {
top.window.opener = top;
top.window.open('', '_self', '');
top.window.close();
}
setTimeout('closeit()', 3000);
</script>
3、wcf捕捉错误
方式一:
serviceHost.Faulted += (object sender, EventArgs e) =>
{
//错误日志
};
{
//错误日志
};
方式二:使得服务实现IErrorHandler
public bool HandleError(Exception error)
{
try
{
if (!EventLog.SourceExists("XXXServiceError"))
{
EventLog.CreateEventSource("XXXServiceError", "XXX Service");
return false;
}
EventLog myLog = new EventLog();
myLog.Source = "XXXServiceError";
myLog.WriteEntry(error.Message);
return true;
}
catch
{
return false;
}
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
FaultException<Exception> faultException = new FaultException<Exception>(
new Exception(), new FaultReason(error.Message));
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, faultException.Action);
}
{
try
{
if (!EventLog.SourceExists("XXXServiceError"))
{
EventLog.CreateEventSource("XXXServiceError", "XXX Service");
return false;
}
EventLog myLog = new EventLog();
myLog.Source = "XXXServiceError";
myLog.WriteEntry(error.Message);
return true;
}
catch
{
return false;
}
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
FaultException<Exception> faultException = new FaultException<Exception>(
new Exception(), new FaultReason(error.Message));
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, faultException.Action);
}
4、便宜的域名解析方法。有时候你可能想要把家里的一台机子做为web服务器或者其它应用提供给外网访问,但是你希望使用真实的域名而不是花生壳或者3322等动态域名,你可以使用如下方法: a、申请一个免费的花生壳或者3322域名 b、在路由器配置花生壳或者3322,让它指向你家里的真实机器 c、添加一个真实域名的另外,让它指向花生壳或者3322的动态域名 d、主机头配置成真实域名 e、如果有多个真实域名站点,同样可以使用这样的方式来做。
5、当前外网IP http://www.ipaddressworld.com/