Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

How to construct HTML page in ASP.NET 1.1 and send it to browser

I need to construct a Redirect page within an ASP.NET application at runtime and then return it so that it will redirect to another site. I have the markup for the page but don't know how to build it up in asp.net/c# code and send it to the browser.  
0
JamesJMcDonnell
Asked:
JamesJMcDonnell
  • 7
  • 3
  • 3
1 Solution
 
nauman_ahmedCommented:
You can simply use Response.Redirect("Page.aspx") to redirect user. Is this what you are looking for?

--Nauman.
0
 
JamesJMcDonnellAuthor Commented:
No because the html page has embedded values that exist only at runtime I need to construct the page at runtime and then use it.
0
 
nauman_ahmedCommented:
I think you can use the meta refresh tag. Add the following between <head></head> tags:

<meta runat=server id="metatag" http-equiv="refresh" content="5"/>

Now you can access it from code and set the value for content attribute:

c#
====
this.metatag.Attributes["content"] = "1";

vb.net
======
metatag.Attributes("content") = "1"

--Nauman.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JamesJMcDonnellAuthor Commented:
I'm doing some processing on an .aspx page and from there need to go to the html page with the embedded values so can't use this. to set the values.
0
 
JamesJMcDonnellAuthor Commented:
So I don't know how set the embedded values. Also the html page has an action parameter set to the url to redirect to with javascript to submit it onload
0
 
nauman_ahmedCommented:
If you can tell me the exact details of what you are trying to achieve, I will be able to tell you a better solution.

--Nauman.
0
 
SammyCommented:
Looks like James is looking to write an html page on the fly based on a set of conditions

string strHTML = "<html><head></head><title>Dyna Page</title><body><p>Hello there </p></body></html>";
      System.IO.StreamWriter sWritter;
        sWritter = System.IO.File.CreateText(Server.MapPath("DynHtmlPage.html"));
        sWritter.WriteLine(strHTML);
        sWritter.Close();
//If you want to display whats written in the DynHtmlPage.html in the aspx file itself you need something like this

Response.WriteFile(Server.MapPath("DynHtmlPage.html"));

Good luck
0
 
JamesJMcDonnellAuthor Commented:
Thanks for your help guys.
Yes I'm trying to write a HTML page on the fly. The html is:
<html>
<head>
<title> 3-D Secure Verification</title>
</head>
<body OnLoad="OnLoadEvent();" >
<form name="mainform" action="acs_url HERE" method="POST">
<noscript>
<br>
<br>
<center>
<h1>Processing your 3-D Secure Transaction</h1>
<h2>
JavaScript is currently disabled or is not supported
by your browser.<br></h2>
<h3>Please click Submit to continue
the processing of your 3-D Secure
transaction.</h3>
<input type="submit" value="Submit">
</center>
</noscript>
<input type="hidden" name="PaReq" value="PaReq HERE">
<input type="hidden" name="TermUrl" value="TERM URL HERE">
<input type="hidden" name="MD" value="MD DATA HERE">
</form>
<SCRIPT LANGUAGE="Javascript" >
<!--
function OnLoadEvent()
{
document.mainform.submit();
}
//-->
</SCRIPT>
</body>
</html>

sammy1971's approach to construct the page seems spot on, and I'm just about to try implementing it. (I don't want to display the page unless this is just for testing to see that it looks right.) The user of the site will only see the page if they do not have javascript enabled. Otherwise it will just redirect to a banks authentication server.
0
 
JamesJMcDonnellAuthor Commented:
After constructing the HTML I tried to redirect to it but got this message:

"Access to the path "c:\inetpub\wwwroot\FTC2\ThreeDSecureRedirectPage.html" is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please Review the stack trace for more information about the error and where it originated in the code.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

I tried to sort this out by adding extension .html to the asp.net_isapi.dll throgh IIS but now getr error "The project is not configured to be debugged. Any ideas what I should do?
0
 
SammyCommented:
Post the code you used to construct and build the page?
the location of the page has to allow anonymous access as well
 
0
 
JamesJMcDonnellAuthor Commented:
Here is the code, iti sn't quite correct as it produces ' instead of " around POST etc. Also the page it is on is HTTPS as it is part of a secure payment transaction.

StringBuilder reDirectPage = new StringBuilder();
reDirectPage.Append("<html><head><title> 3-D Secure Verification</title></head>");
reDirectPage.Append("<body OnLoad= '" + "OnLoadEvent();" + "'" + "><form name= '" + "mainform" + "'" + "action='" + "'");
reDirectPage.Append(AcsUrl);
reDirectPage.Append(" method='" + "POST" + "'" + "><noscript><br><center><h1>Processing your 3-D Secure ");
reDirectPage.Append("Transaction</h1><h2>JavaScript is currently disabled or is not supported by your browser.<br></h2>");
reDirectPage.Append("<h3>Please click Submit to continue the processing of your 3-D Secure transaction.</h3>");
reDirectPage.Append("<input type= '" + "submit" + "'" + " value= '" + "Submit" + "'" + "></center></noscript><input type= '" + "hidden" + "'" + " name= '" + "PaReq" + "'" + "value= '");
reDirectPage.Append(PaReq);
reDirectPage.Append("'" + "<input type='" + "hidden" + "'" + " name='" + "TermUrl" + "'" + " value='" + "http://www.google.com" + "'" + ">");
reDirectPage.Append("<input type='" + "hidden" + "'" + " name='" + "MD" + "'" + " value='");
reDirectPage.Append(MD);
reDirectPage.Append("'" + "></form>");
reDirectPage.Append("<SCRIPT LANGUAGE='" + "Javascript" + "'" + " ><!-- function OnLoadEvent(){document.mainform.submit();}");
reDirectPage.Append("//--> </SCRIPT>");
reDirectPage.Append("</body></html>");
                  
string strHTML = reDirectPage.ToString();
System.IO.StreamWriter sWritter;
// error occurs on next line
sWritter = System.IO.File.CreateText(Server.MapPath("ThreeDSecureRedirectPage.html"));
sWritter.WriteLine(strHTML);
sWritter.Close();
Response.Redirect("ThreeDSecureRedirectPage.html");

0
 
SammyCommented:
This is security issue with this path c:\inetpub\wwwroot\FTC2
aspnet worker is not able to create the page thats why you are getting the error
navigate to the directory c:\inetpub\wwwroot\FTC2 right click on FTC2, go to properties, click on security tab
make sure ASP.NET ((YOUR PC NAME\ASPNET)) have write permission to the directory
0
 
JamesJMcDonnellAuthor Commented:
Thanks. As I mentioned I have another problem now with a web.config file error after trying to add a mapping for .html files. I've posted this as a separate question in the asp.net programming zone. I need to resolve this before I can continue working on the application.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now