簡體   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