CodeFile

CodeFile属性は、ページが参照する分離コードファイルのパスを指定する。

@ Page | Microsoft Docs

これまで、".aspx"ファイルと、".cs"ファイルは同じフォルダ階層にあったが、違うフォルダにしてみる。

src1フォルダを作成
src1フォルダを作成

src1フォルダを作成。
CodeFile.aspxは、

<%@ Page Language="C#" CodeFile="src1/CodeFile.cs" Inherits="CodeFile" %>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title id="title_index">CodeFile</title>
  </head>
  <body>
    <% Response.Write(Method1()); %>
  </body>
</html>

CodeFile属性で、src1のCodeFile.csを参照している。

src1の下にCodeFile.csを置いて
src1の下にCodeFile.csを置いて

src1の下にCodeFile.csを置いて、

Method1で、"src1/CodeFile.Method1 Called!"を返す。

アクセスすると、こうなる。
アクセスすると、こうなる。

アクセスすると、こうなる。

今度はsrc2フォルダを作成
今度はsrc2フォルダを作成

今度はsrc2フォルダを作成。

今度はsrc2のCodeFile.cs
今度はsrc2のCodeFile.cs

今度はsrc2のCodeFile.cs。

"src2/CodeFile.Method1 Called!"を返す。
あとは、

CodeFile属性で、src2のCodeFile.csを指定すると、

&quot;src2/CodeFile.Method1 Called!&quot;になる
"src2/CodeFile.Method1 Called!"になる

"src2/CodeFile.Method1 Called!"になる。

Sample/aspnet/PageDirective/CodeFile/src/PageDirective at master · bg1bgst333/Sample · GitHub