简体   繁体   中英

ASP.NET and dynamic Pages

Is it possible to write a System.Web.UI.Page and stored in an assembly? And how can I make iis call that page?

So I will go deeply...

I'm writing a class like that:

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!!!");
    }

}

That are stored into an assembly.

So Now How can I register that assemply and obtain that http://localhost/test.aspx invoke that class?

Thanks.

Bye.

You'll want to use an HttpHandler or HttpModule to do this.

Registering the assembly is just like registering any assembly -- just define that class in a code file and have the compiled DLL in your bin directory.

Then, as an example, you can create a 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
     }

  }
  .....
}

Your web.config will include something like this in the httpHandlers section

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

Not sure what you're after here. If you set up a deployment project, there's a setting to have it merge all the dll files into a single assembly. Is that what you want? Either way, if you want to reuse the same code behind class for several aspx pages, it is the page declarative (1st line of code in the aspx) that you must change.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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