Reputation: 162
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
Upvotes: 1
Views: 1256
Reputation: 162
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!
Upvotes: 0
Reputation: 77
A simple way might be :
var htmlContent = System.IO.File.ReadAllText(@"C:\Player\Results\xyz.html");
Response.Write(htmlContent);
Upvotes: 0
Reputation: 65
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");
Upvotes: 0
Reputation: 1545
@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);
Upvotes: 2
Reputation: 11173
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.
Upvotes: 0