asp.net错误处理
出现错误发送Email
可以在Global.asax的void Application_Error(Object sender,EventArgs e)
{
//用到了Ssytem.Net.Mail
MailMessage mail=new MailMessage();
mail.from=new MailAddress("automated@contoso.com");
mail.Subject="SIte Error at" +DateTime.Now;
mail.Body="Error Decription"+ ex.Message;
SmtpClient server=new SmtpClient();
server.Host=outgoingMailServerHost;
server.Send(mail);
}
///建壮的错误处理
1。预测问题,具体做饭是把所有可能发生故障代码封装在try/catch/finnally块中,单凭这一点并不能保证不会出现异常,至少还要正确的处理常见的异常
2。不要留下任何未处理的异常,只要遵循这个指导原则,即使未能预测到某种问题,也至少不会让用户看到异常页面,我们可以在页面级和应用程序级实施这一指导原则,不用说,应用程序级别错误处理程序优先于页面级处理程序
3。确保错误页面不会泄漏任何敏感资料,如有必要,区分本地用户和远程用户,并只对本地用户显示消息,本地用户被定义未从Web服务器机器访问应用程序的用户
web.config 中的<customErrors>节
<customErrors mode="RemoteOnly"> mode Off/RemoteOnly/On
更专业点的 一般用mode="RemoteOnly"向本地用户显示详细错误,向远程用户显示错误页面
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="404" redirect="Errro404.aspx"/>
</customErrors>
相关文档:
在Web编程过程中,存在着很多安全隐患。比如在以前的ASP版本中,Cookie为访问者和编程者都提供了方便,并没有提供加密的功能。打开IE浏览器,选择“工具”菜单里的“Internet选项”,然后在弹出的对话框里单击“设置”按钮,选择“查看文件”按钮,在弹出的窗口中,就会显示硬盘里 ......
写图片c:\1.jpg到表cinfo中
private static void AddCinfo()
{
string strSql = "insert into cinfo (srvtitle,csttitle,introduction,logo) values
(@srvtitle,@csttitle,@introduction,@logo)";
S ......
获取与该 Page 对象关联的 HttpResponse 对象。该对象使您得以将 HTTP 响应数据发送到客户端,并包含有关该响应的信息。
一、HttpResponse 类
封装来自 ASP.NET 操作的 HTTP 响应信息。
HttpResponse 类型公开以下成员。
构造函数
名称
说明
HttpResponse
基础结构。初始化 HttpRespons ......
asp.net多频道网站开发架构浅析 http://www.cnblogs.com/Kenny-Jiang/archive/2007/07/31/837900.html 背景:
我们打开门户网站时,往往会看到很多排列紧密的频道列表,如“新闻”、“财经”、“娱乐”等。频道为网站提供了方便的导航功能。
内容描述:
......
1.TextBox txt=(TextBox)PreviousPage.FindControl("TextBox1");
2.在页面注册投递页的属性
<%@ PreviousPageType VirtualPath="crouspostPage.aspx" %>
在crouspostPage.aspx的代码隐藏类中添加
public TextBox TextBox1
{
get(return _textbox);
}
在页面中Response.Write(PreviousPage. ......