【ASP.NET】website轉webapplication


*以下操作都以VS2013為參考;

#新建兩種web項目

1、添加webapplication項目;

2、添加website項目;

 

#比較兩種web項目新建的webform頁面的不同點:

1、文件目錄結構:

  從圖中可以看出webapplication項目中的webform頁面多了*.aspx.designer.cs文件;

  *.aspx.designer.cs文件:通常存放的是一些頁面控件中的控件的配置信息,就是注冊控件頁面。這個東西是窗體設計器生成的代碼文件,作用是對窗體上的控件執行初始化工作;

1 <body>
2     <form id="form1" runat="server">
3     <div>
4         <input id="testinput" runat="server" />
5     </div>
6     </form>
7 </body>

 

 1 namespace WebApplication1 {
 2     
 3     
 4     public partial class App_Default {
 5         
 6         /// <summary>
 7         /// form1 控件。
 8         /// </summary>
 9         /// <remarks>
10         /// 自動生成的字段。
11         /// 若要進行修改,請將字段聲明從設計器文件移到代碼隱藏文件。
12         /// </remarks>
13         protected global::System.Web.UI.HtmlControls.HtmlForm form1;
14         
15         /// <summary>
16         /// testinput 控件。
17         /// </summary>
18         /// <remarks>
19         /// 自動生成的字段。
20         /// 若要進行修改,請將字段聲明從設計器文件移到代碼隱藏文件。
21         /// </remarks>
22         protected global::System.Web.UI.HtmlControls.HtmlInputText testinput;
23     }
24 }

 

2、aspx頁面不同點

  website的頁面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Site_Default.aspx.cs" Inherits="Site_Default" %>

  webapplication的頁面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="App_Default.aspx.cs" Inherits="WebApplication1.App_Default" %>

  不同點:site的為codefile,application為codebehind;

3、aspx.cs文件的不同點

  website的頁面:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 public partial class Site_Default : System.Web.UI.Page
 9 {
10     protected void Page_Load(object sender, EventArgs e)
11     {
12 
13     }
14 }

  webapplication的頁面:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 namespace WebApplication1
 9 {
10     public partial class App_Default : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14             this.testinput.Visible = true;
15         }
16     }
17 }

  不同點:webapp的頁面都有命名空間,而website的頁面沒有;

#將website項目轉換成webapp項目

方法一:

  將website項目的webform頁面拷貝到webapp項目中,

  1)添加.aspx.designer.cs文件;

  2)在.cs文件中加入命名空間;

  3)修改aspx頁面中的codefile為codebehind;

方法二:

  選中webapp項目,選擇菜單欄中的“項目”,選擇“轉換為web應用程序”;

#參考:

https://stackoverflow.com/questions/19561982/visual-studio-2013-missing-convert-to-web-application

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM