动态加载aspx页面

时间:2012-09-19 09:42:10

标签: c# asp.net

我找到了两种为aspx动态加载页面html的方法,但唯一的问题是我的txt文件在另一台服务器上,需要方法在webserver上请求virutalpath或物理路径。

有没有办法可以从url加载azure而不是从filepath加载,或者我只能将字符串传递给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);
    }

0 个答案:

没有答案
相关问题