What is the use of the `CodeFile` attribute in an

2019-07-27 01:43发布

问题:

What is the use of the CodeFile attribute in an ASP.NET page ?

回答1:

CodeFile attribute is used for deploying a single page without deploying the whole application :-

Here are the instructions to deploy a single page to a web application. The following example is using the page /Forms/CreateUser.aspx

In the .cs file change the name of the class to one that doesn't exist. For example, change the following:

public partial class CreateUser : System.Web.UI.Page

To:

public partial class CreateUser1 : System.Web.UI.Page

In the aspx, ascx, master, etc. change the Codebehind to CodeFile and change the name of the class specified in the Inherits attribute to the same name as in the .cs file. For example change the following:

 Page Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true" CodeBehind="CreateUser.aspx.cs" Inherits="Forms.CreateUser"

To:

Page Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true" CodeFile="CreateUser.aspx.cs" Inherits="Forms.CreateUser1"