VS 2010 WebSite网站 使用CodeBehide 方式开发[Web应用程序项目转Web网站]

    由于生成Web应用程序的文件非常大,100M左右,上传到香港太慢,对于运维工作很不现实, 所以只能改用单个源代码文件上传方式,也就是Web网站方式,但VS2010中只提供Web网站转Web应用程序功能,没有提供Web应用程序转网站功能,而且新建WebSite(网站) 只能使用 Single-Page Code 模型来开发网站页面,原Web应用程序全部都是用CodeBehide开发的,如何把WebSite(网站) 使用CodeBehide 方式开发,是个重要问题。经多天研究,终于找到了Web应用程序项目转Web网站的方法。

步骤1:

WebApp(网站应用程序) 工程(右键)-->打包/发布设置-->要部署的项(适用于所有部署方法)-->此项目文件夹中的所有文件。

步骤2:

WebApp(网站应用程序) 工程(右键)-->发布-->发布方式(文件系统)-->发布

步骤3:

在方案中添加现有网站为发布后的文件夹。

步骤4:

批量修改页面 CodeBehind -> CodeFile,

如:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"     CodeBehind="OrderAjax.aspx.cs" Inherits="LinqToOracleWeb.OrderAjax" %>

改为

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"     CodeFile="OrderAjax.aspx.cs" Inherits="LinqToOracleWeb.OrderAjax" %>

步骤5: 修改 Global.asax 文件改为

 1 <%@ Application Language="C#" %>
 2 <%@ Import Namespace="System.Collections.Generic" %>
 3 <script RunAt="server">
 4     //private System.Threading.Timer EmailTimer;        
 5 
 6     void Application_Start(object sender, EventArgs e)
 7     {
 8         // 在应用程序启动时运行的代码
 9     }
10 
11     void Application_End(object sender, EventArgs e)
12     {
13         //  在应用程序关闭时运行的代码
14     }
15 
16     void Application_Error(object sender, EventArgs e)
17     {
18         // 在出现未处理的错误时运行的代码
19     }
20 
21     void Session_Start(object sender, EventArgs e)
22     {
23         // 在新会话启动时运行的代码
24     }
25 
26     void Session_End(object sender, EventArgs e)
27     {
28     }  
29 </script>

现不需要Global.cs文件

步骤6: 并删除所有文件的命名空间,如:

namespace WebApp {

}

成功。 原创文章,转载请注明出处~http://www.cnblogs.com/fiozhao/p/VS2010_WebSite_CodeBehide.html

原文地址:https://www.cnblogs.com/fiozhao/p/VS2010_WebSite_CodeBehide.html