views:

113

answers:

3

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.

A: 

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.

David Hedlund
A: 

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.

Krishna Kumar
I still using reflaction and load Assemblie, but my problem is about to tell IIS to call a specific class.
Neo1975
IIS will not load assemblies; you need to have HTTPhandler factory registered to handle the url patterns and return the page you would like to. Crude way may be to render the response from other page class in your test.aspx.
Krishna Kumar
+1  A: 

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"/>
Clyde
Very, Very Interesting, Thanks!
Neo1975