Let your web App "move".

Source: Internet
Author: User

See here you may ask, the ASP itself is a dynamic site, but also how to move?

What I call here is dynamic loading, dynamic updating. Well, maybe you should ask again. Dynamic Web site is dynamically loaded, dynamically updated. The ASP. NET program is attached to IIS (which is not the only one) running, with code updates that need to be copied to the corresponding directory. The refresh interface will load the latest program. There is no need to restart IIS.

But what I'm talking about here is the dynamic load script. The script here is a C # class file (*.cs) file that is dynamically compiled into a memory run instance.

There may be someone to ask, what is the need for this????

If the program has modifications, modify-compile-copy. Is the latest program, does not affect the online program. But if you think about it, what if it's a small problem? If changes are made to different requirements, a small code modification will be fine. Is it necessary to compile the code and upload the file?

Or you are now around the computer does not have the compilation tool, but need to change some functions of the program, within the scope of the allowed, what should you do?

You may say that this is boring. No need, no use of the scene! 、

Well, I can only say that you haven't met, you ask the people around you to manage the Publisher deployment program, their difficulties, every small bug update, to copy multiple files uploaded to the server is a very troublesome thing.

All right. No nonsense, I came to talk about why I write this article, I have encountered what situation it.

During this time, I give a company's portal site revision, the front desk display page requires a purely static page.

Static pages are also required in the background to update the content of the site, you need to publish the generated static pages are placed in the site directory for access to ~!

The technique I use is to create a content page from a template file, and then save the file.

However, the template file contains some content that needs to be built in C # code and then replaced with the template file content.

C # inside the HTML built inside perhaps tag, perhaps CSS style. There are issues that need to be updated, or needs to be updated, which are common. But once there is an update to change the code, publishing, is a very headache, I have described before.

In the previous article, we developed the game server (iii) load script and server hot update (ii) Full version introduced if the script file is loaded, but the previous test has a problem that has not been tested under ASP.

The problem is reading the referenced assembly issues that the program loads.

Before querying a reference assembly, it looked for the assembly referenced under the referenced assembly, causing the IIS to load some files that could not be loaded.

            var asss = AppDomain.CurrentDomain.GetAssemblies ();             foreach (var in asss)            {                foreach (var in Item). GetModules (false))                {                    Ddlnames.add (item222. fullyqualifiedname);                }            }

You need to change this to look like this, you need to find the assembly referenced under the referenced assembly

            var asss = AppDomain.CurrentDomain.GetAssemblies ();             foreach (var in asss)            {                if (!item. Manifestmodule.isresource () && item. ManifestModule.FullyQualifiedName.EndsWith (".DLL") | | Item. ManifestModule.FullyQualifiedName.EndsWith (". DLL")                {                    Ddlnames.add (item). manifestmodule.fullyqualifiedname);                }            }

We create a Iscript folder to create a ICreateScript.cs interface file

namespace testwebloadscript.iscripts{    publicinterface  icreatescript:ibasescript    {         void string type);}    }

The previous article tells,, is my definition of the script loader, do not know that you loaded those classes, because the script class does not know the class name and instance, so through the interface control, also can be considered as interface programming.

Next we create a Scripts folder and then create the PC file and create the default folder below

Create a indexhtml.temp file to hold the template code

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <title>I am the default version</title></Head><Body>    <formID= "Form1">    <Div>    <%string%>    </Div>    </form></Body></HTML>

The <%string%> above is the replacement keyword

Create a CreateIndexScript.cs file to create an HTML file

namespacetestwebloadscript.scripts.pc.default{ Public classCreateindexscript:icreatescript {stringFilePath ="c:/html/pc/index.html";  Public voidCreatehtml (System.Web.UI.Page Page,stringtype) {            if(Type = ="Default")            {                if(!System.IO.Directory.Exists (System.IO.Path.GetDirectoryName (FilePath)))                {System.IO.Directory.CreateDirectory (System.IO.Path.GetDirectoryName (FilePath)); }                stringHtmlpath = page. Server.MapPath ("/scripts/pc/default/indexhtml.temp"); stringHtmlcontext =System.IO.File.ReadAllText (Htmlpath); using(System.IO.StreamWriter SW =System.IO.File.CreateText (FilePath)) {SW. Write (Htmlcontext.replace ("<%string%>","I'm the default ."+ DateTime.Now.ToString ("YYYY-MM-DD HH:mm:ss:fff"))); }            }        }    }}

Create a index.aspx page

namespacetestwebloadscript{ Public Partial classIndex:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            stringSavepath = Server.MapPath ("/") + system.configuration.configurationmanager.appsettings["ScriptPath"].            ToString (); Sz.Network.LoadScriptPool.LoadScriptManager.GetInstance.LoadCSharpFile (New string[] {savepath}); varScripts = sz.network.loadscriptpool.loadscriptmanager.getinstance.getinstances<icreatescript>(); stringType = This. request["type"]; foreach(varScriptinchscripts) {script. Createhtml ( This, type); }        }    }}

This is our current program requirements, creating an HTML template for index

Publish the Web program at this time.

But suddenly the need, or the template changed, if our generation of HTML, template program is written dead in the code, then we definitely need to change the code. and then compile. and publish again. Generate the latest template page based on data;

It's a lot of trouble.

But after we've made the script,

We copy these two files, copy them once, modify them, and replace them with

QQ version

Of course, you need to modify the script file namespace

Namespace TestWebLoadScript.Scripts.PC.QQ

The QQ version of the static page has been generated.

We copy the same code and create the mobile version;

Build again, the static page generation of each version is completed.

See here do not know what you crossing need to vomit groove???? Welcome Message ~ ~

Let your web App "move".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.