![]() |
#2
yms1232010-01-20 11:54
CS文件为什么要编译生成aspx文件?CS文件可以直接输出网页的内容,就跟JSP的Servlet的原理一样,继承网页的接口就可以。
考虑如下代码 新建一个名为TestWeb的项目 using System; using System.Collections; using using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace TestWeb { /// <summary> /// ProductView 的摘要说明。 /// </summary> public class TestPage:IHttpHandler,IRequiresSessionState { #region 类属性 /// <summary> /// 请求对象 /// </summary> private HttpRequest request; /// <summary> /// 应用程序对象 /// </summary> private HttpApplication application; /// <summary> /// 响应对象 /// </summary> private HttpResponse response; /// <summary> /// 会话对象 /// </summary> private HttpSessionState session; /// <summary> /// 服务器对象 /// </summary> private HttpServerUtility server; #endregion public ProductView() { // // TODO: 在此处添加构造函数逻辑 // } #region IHttpHandler 成员 public void ProcessRequest(HttpContext context) { // TODO: 添加 BBS_ShowTitle.ProcessRequest 实现 this.CreateObject(context); this.response.Write("<HTML>"); this.response.Write("<HEAD>"); this.response.Write("<TITLE>网页输出测试</TITLE>"); this.response.Write("</HEAD>"); this.response.Write("<BODY>"); this.response.Write("<FONT style='font-size:23px;font-family:华文琥珀;color:red'>这是.CS的网页不是.aspx的网页</FONT>"); this.response.Write("</BODY>"); this.response.Write("</HTML>"); } public bool IsReusable { get { // TODO: 添加 BBS_ShowTitle.IsReusable getter 实现 return false; } } #endregion #region 封装方法 /// <summary> /// 创建对象 /// </summary> /// <param name="context">Http上下文对象</param> private void CreateObject(HttpContext context) { this.server=context.Server; this.request=context.Request; this.response=context.Response; this.session=context.Session; } #endregion } } 然后在Web.config的<httpHandlers>(没有<httpHandlers>标记可以手动添加)添加如下代码 <httpHandlers> <add verb="*" path="TestPage.aspx" type="TestWeb.TestPage,TestWeb" /> </httpHandlers> 接下来浏览器里输入 http://localhost/TestWeb/TestPage.aspx 你就会发现代码里的HTML代码被显示出来了,而你在项目文件夹里是找不到TestPage.aspx这个文件的,因为根本不存在。 |
怎样将cs文件编译生成 单独的aspx文件