locked
loading html file into aspx page RRS feed

  • Question

  • User-153404742 posted

    Hi,

    This should be simple but I can't get it to work.  I have an aspx page from where it's redirecting user to another aspx page with an encrypted file path.  In the page, I'm getting the filepath, which is a path to an .html file which I want to load on this aspx page.  I can load this file into an iframe and it loads fine.  However, I don't want to set the iframe src just so that it's not shown in the page source where the file is.  So I'm trying to use streamreader to read and display html in an asp literal control....but it always says the file not found error....any ideas on why?  The path to the file is correct and it works on iframe src and even if I go directly to the path but not when I try to load the html file by reading it and writing it.

    Wednesday, August 8, 2018 6:28 PM

All replies

  • User475983607 posted

    Why don't you follow the advice on in your other post?

    https://forums.asp.net/p/2145131/6223430.aspx?Re+protecting+certain+files+pdf+word+etc+in+asp+net+application

    https://www.mikesdotnetting.com/article/122/simple-file-download-protection-with-asp-net

    Using a handler solves this problem and is the standard method for doing this sort of thing.

    Wednesday, August 8, 2018 6:33 PM
  • User-153404742 posted

    I have the file in app_date folder....and have a handler for it and passing the file name from an aspx page to the ashx handler.  It is downloading the file instead of rendering the html within the calling aspx page.  How do I have the html displayed instead of downloding the file?

     public void ProcessRequest(HttpContext context)
                {
                    if (context.User.Identity.IsAuthenticated)
                    {
                        string filename = context.Request.QueryString["File"];
                        //Validate the file name and make sure it is one that the user may access
                        context.Response.Buffer = true;
                        context.Response.Clear();
                        context.Response.AddHeader("content-disposition", "attachment; filename=" + filename);
                    context.Response.ContentType = "text/html"; //"application/octet-stream";
     
                        context.Response.WriteFile("~/App_Data/" + filename);
                    }
                }
    Wednesday, August 8, 2018 8:09 PM
  • User475983607 posted

    Assign the handler url to the iframe source attribute.

    Wednesday, August 8, 2018 8:12 PM