2

我找到了两种为 aspx 动态加载页面 html 的方法,但唯一的问题是我的 txt 文件在另一台服务器上,并且需要方法询问网络服务器上的虚拟路径或物理路径。

有什么办法可以让我从 url 从 azure 加载而不是从文件路径加载,或者如果我只能将字符串传递给 PageParser 或 BuildManager。

错误:

The relative virtual path 'http:/tplexcontent.blob.core.windows.net/commonresources/test123.txt' is not allowed here. 

 protected void Page_Load(object sender, EventArgs e)
    {
        //Method 1
        var pageView = PageParser.GetCompiledPageInstance("/Page2.aspx", "http://tplexcontent.blob.core.windows.net/commonresources/test123.txt", HttpContext.Current);
        (pageView).ProcessRequest(HttpContext.Current);

        //Method 2
        LoadPage("http://tplexcontent.blob.core.windows.net/commonresources/test123.txt");
    }


    public static void LoadPage(string pagePath)
    {
        // get the compiled type of referenced path
        Type type = BuildManager.GetCompiledType(pagePath);

        // if type is null, could not determine page type
        if (type == null)
            throw new ApplicationException("Page " + pagePath + " not found");

        // cast page object (could also cast an interface instance as well)
        // in this example, ASP220Page is a custom base page
        _Default pageView = (_Default)Activator.CreateInstance(type);

        // call page title
        pageView.Title = "Dynamically loaded page...";
        // process the request with updated object
        ((IHttpHandler)pageView).ProcessRequest(HttpContext.Current);
    }
4

0 回答 0