新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:IDesign C#编码规范(之六)

IDesign C#编码规范(之六)

新客网 XKER.COM 2004-09-28 来源: 收藏本文
大家中秋好,首先非常感谢xiaxia翻译的资料。
由于我对这个文档也是兴趣浓厚,所以就把下面的部分给翻译了。
希望大家多多指教。


4.2 ASP.NET and Web Services
1. 避免将代码放入ASP.NET的ASPX文件中。 所有的代码都应该放在相关代码的Partial类中。
Avoid putting code in ASPX files of ASP.NET. All code should be in the code beside partial class.
2. 放在相关代码的Partial类中的代码,应该调用其他组件,而不是用于写直接的业务逻辑。
Code in code beside partial class of ASP.NET should call other components rather than contain direct business logic.
3. 访问线程变量之前应该检查其是否为null。
Always check a session variable for null before accessing it.
4. 在事务页面或web页面,要将线程存储在SQL server中。
In transactional pages or web services, always store session in SQL server.
5. 在ASP.NET中,避免将服务器控件的Auto-Postback属性设置为true.
Avoid setting to True the Auto-Postback property of server controls in ASP.NET
6. 对于ASP.NET页面,运用智能浏览。
Turn on smart Navigation for ASP.NET pages.
7. 尽量为web服务提供接口。
Strive to provide interfaces for web services.
a) See Appendix A of Programming .NET Components.
8. 总是为web服务提供命名空间和服务描述。
Always provide namespace and service description for web services.
9. 总是为web方法提供描述。
Always provide a description for web methods.
10. 当加入web服务引用时,应该给与有意义的命名。
When adding a web service reference, provide meaningful name for the location.
11. 在ASP.NET页面和web服务页面,要在局部属性里加入线程变量。只有可以访问线程变量的属性和其余使用属性的代码,不是线程变量。
In both ASP.NET pages and web services, wrap a session variables in a local property.
Only that property is allowed to access the session variable, and the rest of the code uses the property, not the session variable.
Public class Calculator: WebService
{
int Memory
{
get
{
int memory = 0;
object state = Session[“Memory”];
if(state != null)
{
memory = (int)state;
}
}
return memory;
set
{
Session[“Memory”] = value;
}
}
[WebMethod(EnableSession = true)]
public void MemoryReset()
{
Memory = 0;
}
}
12. 总是修改客户web服务包装类使其支持cookies.
Always modify client-side web service wrapper class to support cookies.
a) 当你无法知道服务是否服务所用线程的状态时。
You have no way of knowing whether the service uses Session state or not.
Public class Calculator: SoapHttpClientProtocol
{
public CalculatorEx()
{
CookieContainer = new System.Net.CookieContainer();
Url = “http://...”;
}
}


收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐