繁体   English   中英

ASP.NET和动态页面

[英]ASP.NET and dynamic Pages

是否可以编写System.Web.UI.Page并将其存储在程序集中? 以及如何使iis调用该页面?

所以我会深入...

我正在写这样的课:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Reflection;
using WRCSDK;
using System.IO;

public partial class _Test : System.Web.UI.Page
{
    public _Test()
    {
        this.AppRelativeVirtualPath = "~/WRC/test.aspx";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("You are very lucky!!!");
    }

}

将其存储到装配体中。

因此,现在我该如何注册该组件并获取该http://localhost/test.aspx调用该类?

谢谢。

再见

您将要使用HttpHandler或HttpModule来执行此操作。

注册程序集就像注册任何程序集一样-只需在代码文件中定义该类,然后将已编译的DLL保存在bin目录中即可。

然后,作为示例,您可以创建一个IHttpHandlerFactory:

public class MyHandlerFactory : IHttpHandlerFactory
{
  public IHttpHandler GetHandler(HttpContext context, ........)
  {
     // This is saying, "if they requested this URL, use this Page class to render it"
     if (context.Request.AppRelativeCurrentExecutionFilePath.ToUpper() == "~/WRC/TEST.ASPX")
     {
       return new MyProject.Code._Test();
     }
     else
     {
       //other urls can do other things
     }

  }
  .....
}

您的web.config将在httpHandlers部分中包含类似的内容

  <add verb="POST,GET,HEAD" path="WRC/*" type="MyProject.Code.MyHandlerFactory, MyProject"/>

不知道你在这里追求什么。 如果设置了部署项目,则需要进行设置以使其将所有dll文件合并到单个程序集中。 那是你要的吗? 无论哪种方式,如果您想在几个aspx页面的类后面重用相同的代码,则必须更改页面声明性(aspx中的第一行代码)。

很少的选项1.您可以将此程序集作为Visual Studio参考的一部分进行引用。2.使用relfection从测试ASAPX页面加载程序集和类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM