locked
Creating the webpage dynamicaly and saving it to webserver on fly???? RRS feed

  • Question

  • User230766423 posted

    structure of first.aspx is   as follows

                                  1)  It  is having two textboxes with lables  firstname and lastname and Ok button

                                   2) When I click on the ok button   .When I click on 'OK' button  one webpage should be generated automaticaly with its name as

                                     'Textbox value'.aspx  and on other click of 'OK' button .first.aspx should be redirected to this dynamicaly generated page.

                                    How to proceed for this ??? any reference of url  

    Wednesday, September 26, 2007 8:58 AM

Answers

  • User789414417 posted

     There are lots of variables here but you could just have a click handler that gets the values you want and write a file directly to the file system although this is probably not good practice because it would be somewhere for somebody to attack your web site by feeding in information!! You might also get problems with security permissions when the site attempts to write the file (but you can try if you want)

    public void OnClick (object sender, EventArgs e)

    {

        string path = @"c:\temp\" + TextBox.Text + ".aspx";
    if (!File.Exists(path))
    {
    // Create a file to write to.
    using (StreamWriter sw = File.CreateText(path))
    {
    sw.WriteLine("Hello");
    sw.WriteLine("And");
    sw.WriteLine("Welcome");
    }
    }

    Another alternative (like a site I have built) is to have a database to describe the pages you want on your site, use a custom site map provider to generate your menu data and get a URL redirect module (you would have to write it) which can decide what urls are real and what ones are pretend. It can then redirect the pretend ones to a dynamic page passing in the page id as a query parameter and getting that page to display content from the database. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 26, 2007 10:12 AM

All replies

  • User789414417 posted

     There are lots of variables here but you could just have a click handler that gets the values you want and write a file directly to the file system although this is probably not good practice because it would be somewhere for somebody to attack your web site by feeding in information!! You might also get problems with security permissions when the site attempts to write the file (but you can try if you want)

    public void OnClick (object sender, EventArgs e)

    {

        string path = @"c:\temp\" + TextBox.Text + ".aspx";
    if (!File.Exists(path))
    {
    // Create a file to write to.
    using (StreamWriter sw = File.CreateText(path))
    {
    sw.WriteLine("Hello");
    sw.WriteLine("And");
    sw.WriteLine("Welcome");
    }
    }

    Another alternative (like a site I have built) is to have a database to describe the pages you want on your site, use a custom site map provider to generate your menu data and get a URL redirect module (you would have to write it) which can decide what urls are real and what ones are pretend. It can then redirect the pretend ones to a dynamic page passing in the page id as a query parameter and getting that page to display content from the database. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 26, 2007 10:12 AM
  • User230766423 posted

              For the following code to generate webpage dynamicaly ,<!--StartFragment -->

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim txtBody As String = "<html><body>test</body></html>"

        Dim txtName As String = TextBox1.Text & ".aspx"

        My.Computer.FileSystem.WriteAllText(Server.MapPath(txtName), txtBody, False)

        Response.Redirect(txtName)

    End Sub

     .though I imported the  microsoft.visualbasic.myservices .I am not getting
    My.Computer.FileSystem.WriteAllText method, again what kind of security issues I have to face while saving this page on the webserver. How to tackle such situation?

    Thursday, September 27, 2007 2:54 AM