The following is the sample code of the simplest application page. You only need to copy the page to the _ layouts directory.
<% @ Assembly name = "Microsoft. Sharepoint, [full 4-part assembly name]" %>
<% @ Page Language = "C #" masterpagefile = "~ /_ Layouts/application. Master"
Inherits = "Microsoft. Sharepoint. webcontrols. layoutspagebase" %>
<% @ Import namespace = "Microsoft. SharePoint" %>
<SCRIPT runat = "server">
Protected override void onload (eventargs e ){
Spsite sitecollection = spcontext. Current. Site;
Spweb site = spcontext. Current. Web;
Lblsitetitle. Text = site. title;
Lblsiteid. Text = site. Id. tostring (). toupper ();
}
</SCRIPT>
<Asp: Content ID = "Main" runat = "server"
Contentplaceholderid = "placeholdermain">
Site title: <asp: Label id = "lblsitetitle" runat = "server"/>
<Br/>
Site ID: <asp: Label id = "lblsiteid" runat = "server"/>
</ASP: content>
<Asp: Content ID = "pagetitle" runat = "server"
Contentplaceholderid = "placeholderpagetitle">
Hello World
</ASP: content>
<Asp: Content ID = "pagetitleintitlearea" runat = "server"
Contentplaceholderid = "placeholderpagetitleintitlearea">
Hello World
</ASP: content>
This code writes the onload code in the background on the ASPX page, but I prefer code-behind.
For example, if you want to create a customlogin project, there is only one login. ASPX page, put it in the _ layouts directory, you only need to put customlogin. put the DLL in the/layouts/bin directory.
But there is a problem. The _ layouts directory is already named as login. ASPX page. If our page is also placed in the _ layouts directory, it will overwrite the original login. aspx file. Therefore, we can create a subdirectory for our project under the _ layouts directory to store our custom files.
If you want to put the login. ASPX page in a sub-directory under the _ layouts directory, you must create the sub-directory as a virtual directory to use code-behind. That is, after creating the sub-directory customlogin, our login. the storage path of aspx is _ layouts \ customlogin \ login. aspx; while the backend customlogin. the DLL storage path is _ layouts \ customlogin \ bin \ customlogin. DLL.