Answered by:
Show user generated HTML

Question
-
User693597704 posted
Hi Everyone,
I have an area where I need to show a page that was uploaded by a user, and this can vary by user ... I have tried multiple ways but can not figure it out. What is the proper way to do this in Visual Web developer? And how to implement.
as an example Here is the html I am trying to run from the page
removed to avoid confusion
then that area of the page should show this
here is link to what I want people to see in that section
http://www.phillysdesigns2.com/funny/frog1.htm
Sunday, March 9, 2014 5:43 PM
Answers
-
User-821857111 posted
for gigles I created a file and set my iframe "Src" to it and I get nothing stillYou should be passing a url to the src attribute, not a file path.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 16, 2014 3:18 PM -
User693597704 posted
nevermind got it working perfectly naow.... I just added on the recordnumber to the end the file so it it
System.IO.File.WriteAllText(Server.MapPath("~/") + "001/temprules" + TournamentNumber + ".htm", Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text)) FilePath = "001/temprules" + TournamentNumber + ".htm" RulesFrame.Attributes("Src") = FilePath 'Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) RulesFrame.Visible = True Rules.Text = Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) Rules.Visible = False
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 16, 2014 9:57 PM
All replies
-
User693597704 posted
OK so after a week of searching I think I am getting close here.... It looks like I need to use iframe. so in my aspx file I have
<div> <iframe width="450px" height="450px" scrolling="auto" runat="server" ID="RulesFrame"></iframe> </div>
then in codebehind on my page load I have
Dim src
RulesFrame.Attributes(src) = Server.HtmlDecode("http://www.phillysdesigns2.com/funny/frog1.htm")it returns this error when I run under debug as the page is loading..... . The string parameter 'key' cannot be null or empty.
Parameter name: key.Monday, March 10, 2014 2:59 AM -
User693597704 posted
OK so I believe I have this working now .... sorta
for my Iframe I now have
RulesFrame.Attributes("Src") = Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text)
but it gives an Server error stating "HTTP Error - 400 Bad request"When I look at the saved code going into the iframe it looks right
I have looked through here and tried what some said fixed their problems with no success
This page is not published yet I am viewing it on localhost, I also tried debugging under IIS and got
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (<).
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.
Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (<).
Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (<).] System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9561124 System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
what is causing this? this code works elsewhere
Monday, March 10, 2014 12:15 PM -
User-166373564 posted
Hi Steve
A potentially dangerous Request.Path value was detected from the client (<).For this issue, I think you could refer the article below to learn how to remove characters to avoid .NET Request Validation Error - A potentially dangerous Request.Path value was detected from the client,
How to remove characters to avoid .NET Request Validation Error
Moreover, place in your where you want to procees html, validateRequest="false"
hope it helps.
Best regards
Friday, March 14, 2014 5:35 AM -
User693597704 posted
so if I follow what is said there and replace those characters with "-" won't it then not run the HTML code, and run it as if it was just text?
Saturday, March 15, 2014 1:43 AM -
User-821857111 posted
show a page that was uploaded by a userHow is the "page" uploaded? Are you able to write it to a file and use that as the src for your iframe?
Saturday, March 15, 2014 10:41 AM -
User693597704 posted
I save it in a database, then assign the database location to the iframe. so the whole "html page code" is just saved in the database. I do not write it to a file, should I be doing this instead? From reading online, here is what I have changed so far in attempts to get it to work
here is codebehind
RulesFrame.Attributes("Src") = Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) RulesFrame.Visible = True
here is what I now have for aspx page
<div> <iframe ID="RulesFrame" Width="690px" scrolling="auto" runat="server" validateRequest="false" height="988"></iframe> </div>
here is what I now have in my web config
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="*,%,:" /> <pages validateRequest="false" />
Saturday, March 15, 2014 11:07 AM -
User-821857111 posted
I think I would go for the temp html file option. It's a lot simpler. You can grab the content in the RowDataBound event from the DataItem that the GridView is bound to. It save all the other messing about.
Saturday, March 15, 2014 11:14 AM -
User693597704 posted
how would I do this? and does it open a new page? I can't open it as a new page, it needs to remain as a section of a page
Sunday, March 16, 2014 2:31 AM -
User-821857111 posted
It's the RowDataBound event you need: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound(v=vs.110).aspx
And you can use the File.WriteAllText method to create the file from the content once you have it. Then simply set the iframe src to the location of the file.
No, it won't open in a new window if you use an iframe.
Sunday, March 16, 2014 4:52 AM -
User693597704 posted
But I am not using gridview, I am using detailsview and then that is set as not visible so I basically am just using it as a place holder for various info and not seen by users..I am confused
also for gigles I created a file and set my iframe "Src" to it and I get nothing still
FilePath = Server.MapPath("~/App_Data/temprules.txt") 'System.IO.File.WriteAllText(FilePath, Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text)) RulesFrame.Attributes("Src") = filepath 'Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) RulesFrame.Visible = True
Sunday, March 16, 2014 1:12 PM -
User-821857111 posted
for gigles I created a file and set my iframe "Src" to it and I get nothing stillYou should be passing a url to the src attribute, not a file path.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 16, 2014 3:18 PM -
User693597704 posted
got it thank you
Sunday, March 16, 2014 4:21 PM -
User693597704 posted
Hi Mike,
thanks for all your help. The situation I am having now is when I go back to open a different file. It is the same as the previous....Do I have to exit the file write or something for it to open and write different HTML?
System.IO.File.WriteAllText(Server.MapPath("~/") + "001/temprules.htm", Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text)) FilePath = "001/temprules.htm" RulesFrame.Attributes("Src") = FilePath RulesFrame.Visible = True
Sunday, March 16, 2014 9:23 PM -
User693597704 posted
nevermind got it working perfectly naow.... I just added on the recordnumber to the end the file so it it
System.IO.File.WriteAllText(Server.MapPath("~/") + "001/temprules" + TournamentNumber + ".htm", Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text)) FilePath = "001/temprules" + TournamentNumber + ".htm" RulesFrame.Attributes("Src") = FilePath 'Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) RulesFrame.Visible = True Rules.Text = Server.HtmlDecode(DetailsView1.Rows.Item(13).Cells(1).Text) Rules.Visible = False
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 16, 2014 9:57 PM