1

I wish to load a local html page in my web form. The code I'm using looks like

Response.Redirect("C:\Player\Results\xyz.html", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();

I know there are similar questions asked but none helped me. It would be very much helpful if someone can let me know where I'm going wrong

Thank youenter image description here

m_beta
  • 132
  • 15

6 Answers6

2

@m_beta you are using the physical path for redirection. This will necessiate you to change the code whenever you move your code location. Use relative path instead.

It would be something like below. You need to correct the path according to your location.

Response.Redirect("~/admin/paths.aspx", false);
Ajith
  • 1,447
  • 2
  • 17
  • 31
  • 1
    This was the **Key part** of the question to use **relative path** instead of using physical path. – m_beta Jan 16 '20 at 07:35
  • @m_beta Have you got it working when you changed to use relative part? Up vote or Mark as answer if it works. – Ajith Jan 16 '20 at 07:59
0

Redirecting to a http / https url that will respond with the static content is one thing, but no browser is going to load a local file. If browsers did that it would introduce a massive security risk.

Jeremy Lakeman
  • 9,515
  • 25
  • 29
  • Okay Actually I have a service running which generates a html file as output file. So any hint on how can I load the html file in web form Because if I do so then everyone can view the output file using URL. – m_beta Jan 16 '20 at 05:39
  • So you are running an external process to produce the html? Then you want https://stackoverflow.com/questions/10830212/how-to-serve-html-file-from-another-directory-as-actionresult – Jeremy Lakeman Jan 16 '20 at 05:47
  • The above given link works for me and thanks for the same but the 2nd part of your answer _but no browser is going to load a local file_ is quite misleading I would like to say. – m_beta Jan 16 '20 at 07:33
  • I wouldn't call it misleading. Attempting to redirect to a file:// url would be a security concern. Having the web server, running on the local machine, return the contents of a local file, is completely different. – Jeremy Lakeman Jan 17 '20 at 04:52
0

You can add redirection like this also

If localhost, check your localhost value add like below

Response.Redirect("http://localhost:51043/xyz.html"); 

Live site

Response.Redirect("http://xyzdotcom/xyz.html"); 
Mr doubt
  • 51
  • 1
  • 10
  • 42
0

A simple way might be :

  var htmlContent = System.IO.File.ReadAllText(@"C:\Player\Results\xyz.html");
  Response.Write(htmlContent);
0

Use IFrame and use it;s SRC property to call your html page

Shyam
  • 182
  • 1
  • 14
0

There are many ways to do it but I would like to mention the 2 which worked for me

In this approach the response will be redirected to the page you are passing.

Response.Redirect("~/Results/xyz.html", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();

In this below mentioned approach the content of the html page which you wish to render will be read and then passed on using OutputStream.

var encoding = new System.Text.UTF8Encoding();
var htm = System.IO.File.ReadAllText(Server.MapPath("/Results/Html/") + "xyz.html", encoding);
byte[] data = encoding.GetBytes(htm);
Response.OutputStream.Write(data, 0, data.Length);
Response.OutputStream.Flush();

Thanks to everyone who has contributed here!

m_beta
  • 132
  • 15