1. Problem Introduction During the development process of VS2005 website, website publishing has always been a problem. The website created by VS2005 has several default directories: App_Code, App_Data, App_Themes...
If it is a cs/vb file, such as UploadFile.cs class UploadFile, this class file does not have a visible aspx file, then this file must be placed in the App_Code directory, otherwise this class is inaccessible in the VS2005 website. Then Just put it in, but when compiling (my VS2005 is the Team version, the generation does not respond. It feels like checking the code again, and can only use the publishing website to precompile. I don’t know what other versions are like.) The problem arises. After selecting the publishing website, it will let you choose how to publish. Generally, you can choose the default. That way the number of generated dlls will be smaller. After publishing, there will usually be App_Code.compiled, App_Code.dll in the bin directory. App_Web_ (random characters).dll, referenced dll and other files. The problem lies here. If you want to make a virtualization-free program, wouldn't it be possible that two App_Code.dlls need to be placed in the bin directory? Will there be no conflict? Also, if the program changes once and needs to be republished, that's it. Look at the good things VS2005 has done. inherits="MyCodeGif, App_Web_vf3ukhnv" was originally a MyCodeGif.aspx file and a MyCodeGif.aspx.cs file. Now the MyCodeGif.aspx file inherits from MyCodeGif, App_Web_vf3ukhnv. It can be seen that MyCodeGif is a class defined by MyCodeGif.aspx.cs. App_Web_vf3ukhnv is the name of a dll file in the bin folder. If you try to publish it again, a more troublesome question will arise. Why is the MyCodeGif.aspx page inherited from MyCodeGif, App_Web_qwdwqd? The compiled assembly names are different!
2. The relationship between pages and classes in ASP.Net
In ASP.Net, pages can inherit from classes and can have multiple inheritance. for example
MyCodeGif.aspx page file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCodeGif.aspx.cs" Inherits="MyCodeGif" %>MyCodeGif.aspx.cs is like this
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FreeCodeNum;
public partial class MyCodeGif : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//.....logic
}
}
It can be seen that the MyCodeGif.aspx page inherits from the class MyCodeGif
and can also be inherited in this way
MyCodeGif.aspx page file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCodeGif.aspx.cs" Inherits="MyCodeGif" %>
This is what MyCodeGif.aspx.cs looks like
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FreeCodeNum;
public partial class MyCodeGif : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
//.....logic
}
}
PageBase.cs like this
using System;
using System.Web;
using System.Collections;
/**//// <summary>
/// Summary description of PageBase
/// </summary>
public class PageBase : System.Web.UI.Page
{
publicPageBase()
{
}
}
Like my MyCodeGif.aspx page file, I can even
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCodeGif.aspx.cs" Inherits="PageBase" %>That is, the page directly inherits from the PageBase class.
Conclusion: ASP.Net pages can inherit from [Inherited from the parent class of the System.Web.UI.Page class] extended subclasses.
3. Solution: You can also customize the assembly name in VS2005 - that is, when creating Project time, not website time. In other words, after the website you created has been written, you can re-create a project and then recompile the website code. You may need to change the inheritance of the aspx file after finishing it, but you may not need to change it. It depends on how you save it, because the inheritance of the aspx file is only related to the class name (if there is a namespace, the namespace must also be specified). MyCodeGif.aspx page file can be changed to
<%@ Page Language="C#" AutoEventWireup="true" Inherits="PageBase" %>
Remove CodeFile="MyCodeGif.aspx.cs" inside.
In this way, the website can be published in the same way as VS2003. The process may be a bit complicated, but I think it is quite useful for later maintenance. After all, I am used to VS2003. And I can do the same virtualization-free programs as in 2003.
Complete text. Hope it can be useful to everyone.
Author: Xie Ping, Sunset Track 2006-5-27