Neo1975
Neo1975

Reputation: 124

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.

Upvotes: 1

Views: 211

Answers (3)

Clyde
Clyde

Reputation: 8145

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"/>

Upvotes: 1

Krishna Kumar
Krishna Kumar

Reputation: 8211

Few options 1. You can refer to this assembly as part of visual studio references 2. Use relfection to load the assembly and class from your test ASAPX page.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129832

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.

Upvotes: 0

Related Questions