Asp.net 随记 Part5 (91-121 )
http://www.cnblogs.com/teracy/archive/2008/12/07/1349715.html
121.使用IE不能访问ftp的原因
http://www.cidu.net/Article/jiaocheng/qtjc/200704/8202.html
120.TransactionScope的正确用法
http://blog.csdn.net/greystar/archive/2006/11/01/1359960.aspx
119.List<String>,String Array 绑定到数据控件上的方法
http://www.cnblogs.com/lpy126210/archive/2009/01/04/1368168.html
118.使用 Visual C# .NET 将字符串转换为词首字母大写或小写或大写
http://support.microsoft.com/kb/312890/zh-cn
117.The Best Visual Studio 2010 Productivity Power Tools, Power Commands and Extensions
116.2005年9月的MSDN Magazine中Fast, Scalable, and Secure Session State Management for Your Web Applications详细讲解了设计和部署高性能和安全会话的解决方案。
114.理解Session State模式+ASP.NET SESSION丢失FAQ
113.基于.NET Framework 4.0的解决方案部署
112.配置IIS 6.0 HTTP压缩
111.set nocount on
最近在弄一个数据库相关的东西,
一个是如果有大批量的loop动作写入一个庞大的表的话,不采用事务将导致及其缓慢的IO延迟和性能的损耗,但是如果用数据库事务将大大的提升执行效率和性能;
对于数据库,尤其是存储过程中加入set nocount on的话,数据库将不会把done_in_proc这类的消息发送给客户端,这将显著的提升执行性能(因为减少网络传输流量)。
110.img标签的src=""会引起的Page_Load多次执行
109.Asp.Net4.0/VS2010新变化(2):网站自动预热
http://www.cnblogs.com/yjmyzz/archive/2010/03/05/1679089.html
108..NET 4.0 环境下无法直接运行 .NET 2.0 程序的问题,当然目前解决了
http://www.cnblogs.com/worksguo/archive/2010/02/10/1666939.html
107.XSS/XST攻击
http TRACE 跨站攻击漏洞测试与防御修复
http://www.anywolfs.com/liuhui/article.asp?id=368
XSS:要防止XSS跨站式脚本攻击主要是要在查询字符串(QueryString),表单数据(PostData)以及Cookie甚至HTTP报头(Header)中防止掉一些javascript关键字和一些敏感的字符(单引号,分号)以及SQL语言的关键字,以及防止他们使用encode编码。
106.如何隐藏console窗口
解决方案: 把工程属性设置里的"output type"设置成windows application即可。 |
105.实体填充
public class ChannelsEntity {
public Int32 ChannelID { get; set; }
public String ChannelName { get; set; }
public String SID { get; set; }
public String DefaultUrl { get; set; }
public String VisitCount { get; set; }
public List<SubChannelsEntity> subChannelsEntity { get; set; }
}
/// <summary>
/// 子渠道信息实体
/// </summary>
[Serializable]
public class SubChannelsEntity {
public Int32 SubChannelID { get; set; }
public Int32 ChannelID { get; set; }
public String SID { get; set; }
public String CID { get; set; }
public String Url { get; set; }
public String Memo { get; set; }
}
/// <summary>
/// 获取渠道和子渠道的URL
/// </summary>
/// <returns></returns>
internal List<ChannelsEntity> GetChannelSubChannelInfo () {
var command = BuilderCommand ( SEL_ChannelSubChannelInfo , false );
var ceList = new List<ChannelsEntity> ();
var ce = new ChannelsEntity ();
var sceList = new List<SubChannelsEntity> ();
using ( var idr = db.ExecuteReader ( command ) ) {
while ( idr.Read () ) {
if ( ceList.Count == 0 ) {
AddItemInList ( idr , sceList , ceList , ce );
}
else {
var SID = CommonFunc.ConvertObjectToString ( idr["SID"] );
if ( ce.SID == SID ) {
AddSubItemInList ( idr , sceList , ce );
}
else {
ce = new ChannelsEntity ();
sceList = new List<SubChannelsEntity> ();
AddItemInList ( idr , sceList , ceList , ce );
}
}
}
}
return ceList;
}
private void AddItemInList (IDataReader idr , List<SubChannelsEntity> sceList ,
List<ChannelsEntity> ceList , ChannelsEntity ce) {
ce.SID = CommonFunc.ConvertObjectToString ( idr["SID"] );
ce.DefaultUrl = CommonFunc.ConvertObjectToString ( idr["DefaultUrl"] );
AddSubItemInList ( idr , sceList , ce );
ceList.Add ( ce );
}
private void AddSubItemInList (IDataReader idr , List<SubChannelsEntity> sceList , ChannelsEntity ce) {
sceList.Add ( new SubChannelsEntity () {
CID = CommonFunc.ConvertObjectToString ( idr["CID"] ) ,
Url = CommonFunc.ConvertObjectToString ( idr["Url"] ) ,
} );
ce.subChannelsEntity = sceList;
}
104.使用JS加载图片的问题(在IE6(IE6.2900.5512以前版本都有这个问题))
//IE6 加载无显示(其他OK)
$("#photoShow").empty().append($(pic).html()).show();
解决方案:
原因:IE6 BUG
描述:dom.innerHTML=""这种方式赋值时,如果有资源文件,IE6不会从缓存里读而是重新请求一遍。。
但请求过程中会大概率丢失。。
资源:http://hi.baidu.com/bdui/blog/item/a29edfef34b2cc15fcfa3c62.html
代码:
var _src,_imgid;
function showpicInIe6()
{
var h="<img src='"+_src+"' imgid='"+_imgid+"'></img>";
document.getElementById('photoShow').innerHTML = h;
document.getElementById('photoShow').style.display="block";
}
function showBigpic(pic) {
if($.browser.msie)
{
_src=$(pic).children().attr("src");
_imgid=$(pic).children().attr("imgid");
setTimeout("showpicInIe6()",500);
}
else
{
$("#photoShow").empty().append($(pic).html()).show();
}
$("#curIndex").html($(pic).attr("rel"));
}
103.获取本周第一天、最后一天
DateTime.Now.AddDays ( Convert.ToDouble ( ( 1 - Convert.ToInt16 ( DateTime.Now.DayOfWeek ) ) ) ).ToShortDateString ()
DateTime.Now.AddDays ( Convert.ToDouble ( ( 7 - Convert.ToInt16 ( DateTime.Now.DayOfWeek ) ) ) ).ToShortDateString ()
102.Caching Images in ASP.NET
http://www.codeproject.com/KB/aspnet/CachingImagesInASPNET.aspx
http://ssbird.blog.51cto.com/277690/59297
101.Windows 2003中如何启动IIS6的GZIP压缩网页传输(补充)
100.webservice里能返回dataset而不能返回datatable的原因
原因是设计是留下来的,datatable、datarow、dataview、dataviewmanager这几个对象不是连续的,所以不能在webservices中被返回。
解决办法是:
用dataset返回而不用datatable返回,dataset可以含有多个datatable。
99.在Web Service中实现Transaction
http://www.newasp.net/tech/net/11304.html
98.Visual Studio 2008中的新元件TableAdapterManager
97.WebService 支持的数据类型
代码
ASP.NET WebService 使用 XmlSerializer 进行序列化操作,对于自定义类型要注意以下几点:
1. 只能序列化可读写公共属性和字段。只读属性(get;)、只读字段(readonly)、常量(const)以及所有的非 public 数据成员都不会被序列化。
2. 自定义类型必须具有不接受任何参数的默认构造函数。
3. 不能序列化方法。客户端生成的代理对象不包含任何自定义类型方法(不是WebMethod)。
基于以上几点,因此我们最好只定义纯粹用来传输复合数据的数据类型(Data Object)。
以下是一些演示代码。
基元类型
[WebService(Namespace = "http://www.rainsts.net/", Description="我的Web服务")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
}
[WebMethod]
public DateTime GetNowTime()
{
return DateTime.Now;
}
[WebMethod]
public string[] GetStringArray()
{
return new string[] { "a", "b", "c"};
}
[WebMethod]
public float[] GetFloatArray()
{
return new float[]{1F, 2F, 3F};
}
[WebMethod]
public byte[] GetBytes()
{
return System.IO.File.ReadAllBytes(@"c:\windows\notepad.exe");
}
}
枚举 Enum
public enum Sex
{
Female,
Male
}
[WebService(Namespace = "http://www.rainsts.net/", Description="我的Web服务")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
}
[WebMethod]
public Sex GetSex()
{
return Sex.Female;
}
[WebMethod]
public Sex[] GetAllSex()
{
return Enum.GetValues(typeof(Sex)) as Sex[];
}
}
结构 Struct
结构体默认就会创建无参数构造方法,且不允许自定义。
public struct MyStruct
{
public int X;
public int Y;
public MyStruct(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[WebService(Namespace = "http://www.rainsts.net/", Description="我的Web服务")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
}
[WebMethod]
public MyStruct GetMyStruct()
{
MyStruct st = new MyStruct(15, 16);
return st;
}
[WebMethod]
public MyStruct[] GetMyStructs()
{
return new MyStruct[] { new MyStruct(1, 2), new MyStruct(3, 4) }; ;
}
}
类型 Class
public struct MyStruct
{
public int X;
public int Y;
public MyStruct(int x, int y)
{
this.X = x;
this.Y = y;
}
}
public class MyClass
{
public MyClass()
{
myStruct = new MyStruct();
}
public MyClass(int x, int y, string name) : this()
{
myStruct.X = x;
myStruct.Y = y;
this.name = name;
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private MyStruct myStruct;
public MyStruct MyStruct
{
get { return myStruct; }
set { myStruct = value; }
}
public void Test() // 客户端代理不会生成该方法。
{
Console.WriteLine(name);
}
}
[WebService(Namespace = "http://www.rainsts.net/", Description="我的Web服务")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
}
[WebMethod]
public MyClass GetMyClass()
{
return new MyClass(1, 2, "name1");
}
[WebMethod]
public MyClass[] GetMyClassArray()
{
return new MyClass[] { new MyClass(1, 2, "name1"), new MyClass(2, 3, "name2") }; ;
}
}
96.VS 2008 Server Explorer 添加数据库连接出错
http://www.cnblogs.com/rchen/archive/2009/02/22/1396156.html
Error:
Unable to add data connection.
Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
Method:
Microsoft SQL Server 2008 Management Objects
- X86 Package
- (SharedManagementObjects.msi) - 3225 KB
X64 Package- (SharedManagementObjects.msi) - 3895 KB
IA64 Package- (SharedManagementObjects.msi) - 5640 KB
The SQL Server Management Objects (SMO) is a .NET Framework object model that enables software developers to create client-side applications to manage and administer SQL Server objects and services. This object model will work with SQL Server 2000, SQL Server 2005 and SQL Server 2008.
Note:
- Microsoft SQL Server 2008 Management Objects Collection requires
Microsoft Core XML Services (MSXML) 6.0
- , Microsoft SQL Server Native Client, and Microsoft SQL Server System CLR Types. These are available on this page.
- Audience(s):
Customer, Partner, Developer
95.windows2003安装MSN 提示 os_check:0x80280004的解决办法
1)到http://angusj.com/resourcehacker/里下载Resource Hacker工具,
Resource Hacker 可以修改32位的 Windows 可执行文件,非常好用的一款免费工具。
2)运行 压缩包下的ResHacker.exe,打开 下载的 wlsetup-all.exe,
打开左侧目录 CONFIG -> CONFIG0 -> 0,找到文件中如下 XML 代码:
<os productType="workstation"/> 把其中的 workstation 替换为 Server
3)点击Compile Script ,击点FIle -> Save,退出
4)运行 wlsetup-all.exe,即可安装。
94.window.close()关闭不提示
<a onclick="window.opener=null;window.open('','_self','');window.close();" href="javascript:void(0);"> 关闭不提示 </a>
关键是window.open('','_self','');
93.TextBox ReadOnly的问题
http://www.cnblogs.com/lizhiwen/archive/2007/03/29/692613.html
http://blog.joycode.com/saucer/archive/2006/05/11/75741.joy
92.解决Windows 7无法访问Windows 2003共享的问题
今天访问另一台Windows Server 2003的共享,无论怎么输入都提示密码错误。
解决方法:
- 首先确认一下控制面板-系统和安全-windows防火墙-允许的程序里打开了“文件和打印机共享”
- 开始=>运行... =>gpedit.msc=>本地计算机策略=>计算机配置=>Windows设置=>安全设置=>本地策略=>安全选项。找到:“网络安全:LAN管理器身份验证级别”项,默认值“没有定义”改为“发送LM & NTLM响应”
91.II7超时(Web site worker process has been terminated by IIS)
http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/10/24/debug-terminated-by-iis7.aspx
http://dyardy.spaces.live.com/blog/cns!812B0DF85863A595!389.entry
系列:
Asp.net 随记 Part2 (31- 52)