Reputation: 17
I have code to dynamic create a new page in my asp.net website, and its work great. But when i create new page and go to that page first load is quite long 20+ second this because probably when i create new page all website restart?
How do I prevent to my application restarts every time I create a new page?
II7
This is just a sample code to see how I create new pages, code is not the same but similar :
string fielName = Server.MapPath("~/file.aspx");
// create a writer and open the file
TextWriter tw = new StreamWriter(fielName);
// write a line of text to the file
tw.WriteLine(@"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeFile=""file.aspx.cs"" Inherits=""file"" %>
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head runat=""server"">
<title></title>
</head>
<body>
<form id=""form1"" runat=""server"">
<div>
</div>
</form>
</body>
</html>
");
// close the stream
tw.Close();
tw = new StreamWriter(fielName + ".cs");
// write a line of text to the file
tw.WriteLine(@"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class file : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(""new File "");
}
}
");
// close the stream
tw.Close();
Upvotes: 1
Views: 125
Reputation: 20693
You can't prevent application pool recycle when creating new aspx files, recompiling these aspx eventually requires application pool recycle, so IMO you got a good answers on that forum.
To put it shortly, you are doing it wrong. There is no need to create pages on the disk, your code behind and markup will produce different pages based on data from database.
You have to change that because that way this will NOT work.
For example if you have TextBox in markup :
<asp:TextBox ID="txtDataFromDB" runat="Server"/>
And then in code behind :
protected void Page_Load(object sender, EventArgs e)
{
txtDataFromDB.Text = GetDataFromDatabase();
}
Your page will show different content according to data you get from DB.
Upvotes: 1
Reputation: 1169
You use the lifecylce ?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GenerateWebsite();
}
}
http://msdn.microsoft.com/en-us/library/bb470252%28v=vs.100%29.aspx -> Have you read this allready ?
Upvotes: 0