上一篇:IDesign C#编码规范(之七) >>
IDesign C#编码规范(之六)
由于我对这个文档也是兴趣浓厚,所以就把下面的部分给翻译了。
希望大家多多指教。
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://...”;
}
}
下一篇:在C#中如何在客户端接收信件 >>
相关文章:
- · C#程序员面试(一)答案
- · 使用智能设备扩展在 C# 中开发自定义控件
- · C#规范漫谈
- · Simple Image Slide Show C# edition
- · 用C#制作作屏幕捕获程序
- · 让窗体飘动起来--C#中Timer组件用法
- · C#做托盘程序
- · 三值逻辑的C#实现
- · 关于C#中的结构(下)
- · C#函数的参数中返回结构数组
- · C#异常处理机制初步
- · c#高級編程記錄--第一章
- · 关于C#中的结构
- · C#编程打造自己的IE浏览器
- · 用C#创建可拖动窗体
- · C#中的委托
- · C# variable criterion
- · C# FAQ
- · C#学习杂记
- · C#2.0的特性
- · 将控件中的数据输出保存到本地excel或word中,同时保存图片到本地(c#)
- · C#分析数据库结构,使用XSL模板自动生成代码
- · 捕捉DataGrid的双击事件(C#版本)
- · C#设计模式讨论——开篇闲话
- · C#如何取硬件标志
- · 使用C#制作《邮件特快专递》
- · 使用C#调用外部Ping命令获取网络连接情况
- · C# 编程规范
- · 教你在C#中如何读写INI文件
- · C#数组篇讲解
- · C#如何取硬件标志
- · C#语法入门1
- · 如何使用.NET生成C#源代码
- · C#中控制流程
- · C#中数组,类型转换
- · C#语言中变量的使用和注意事项
- · C#独立域名查询
- · 在C#里面调用带有回调函数和自定义结构体的DLL的例程
