1.新建web应用程序,清除应用程序中默认生成的文件

2.将网站中的文件复制到web应用程序中

3.将网站的App_Code文件重命名

4.右键web应用程序,点击将转换为应用程序项目

5.添加引用

6.添加命名空间

搜索并添加名字空间

       static ArrayList ReplaceClassFile(DirectoryInfo dir)//搜索文件夹中的文件
{
ArrayList FileList = new ArrayList(); FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
{
FileList.Add(fi.FullName);
//Console.WriteLine(fi.FullName); //class namespace 檢測是否包含namespace 不包含則添加namespace
string filecontent = ReadFile(fi.FullName);
if (filecontent.IndexOf("namespace") < && fi.Extension==".cs")
{
int classindex = filecontent.IndexOf("public class");
if (classindex < ) classindex = ;
filecontent = filecontent.Insert(classindex, "\r\nnamespace xxx\r\n{\r\n");
int lastindex=filecontent.LastIndexOf("}");
filecontent=filecontent.Insert(lastindex, "\r\n }\r\n ");
Console.WriteLine("不存在namespace" + fi.FullName + "\n\t" ); if (WriteFile(fi.FullName, filecontent))
{
Console.WriteLine("新增namespace成功");
} }
} DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
{
ReplaceClassFile(d);
}
return FileList;
} static ArrayList ReplaceAspxPage(DirectoryInfo dir,string namespaceString)//搜索文件夹中的文件
{
ArrayList FileList = new ArrayList(); FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
{
FileList.Add(fi.FullName);
//Console.WriteLine(fi.FullName); //class namespace 檢測是否包含namespace 不包含則添加namespace if (fi.Extension == ".cs" && (fi.Name.IndexOf("aspx.cs") > || fi.Name.IndexOf("designer.cs") > ))
{
string filecontent = ReadFile(fi.FullName);
if (filecontent.IndexOf("namespace") < )
{
int classindex = filecontent.IndexOf("public partial class");
if (classindex < ) classindex = ;
filecontent = filecontent.Insert(classindex, "\r\nnamespace " + namespaceString + "\r\n{\r\n");
int lastindex = filecontent.LastIndexOf("}");
filecontent = filecontent.Insert(lastindex, "\r\n }\r\n ");
Console.WriteLine("不存在namespace" + fi.FullName + "\n\t"); if (WriteFile(fi.FullName, filecontent))
{
Console.WriteLine("新增namespace成功");
}
}
} if (fi.Extension == ".aspx")
{
string filecontent = ReadFile(fi.FullName);
if (filecontent.IndexOf("Inherits=\"xxx") < )
{ filecontent = filecontent.Replace("Inherits=\"", "Inherits=\"" + namespaceString + "."); Console.WriteLine("不存在namespace" + fi.FullName + "\n\t"); if (WriteFile(fi.FullName, filecontent))
{
Console.WriteLine("新增namespace成功");
}
}
}
} DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
{
ReplaceAspxPage(d, namespaceString);
}
return FileList;
}

将网站转换为Web应用程序的更多相关文章

  1. VS2013,asp.net网站转换为web应用程序

    此功能已经不在右键菜单里了,而在主菜单中的“项目-->转换为WEB应用程序”

  2. 网站和Web应用程序的区别

    新建项目里面的(ASP.NET Web 应用程序)主要是做B/S系统的,与winform的开发方式类似.新建网站(ASP.NET 网站)是主要开发网站的.其实你只要跟着教程做就行了.具体区别如下(借鉴 ...

  3. WEB服务器4--IIS中网站、Web应用程序和虚拟目录

    网站.Web应用程序和虚拟目录 在IIS中可以创建网站.Web 应用程序和虚拟目录,以便与计算机网络上的用户共享信息. “网站”.“Web 应用程序”和“虚拟目录”这三个概念的关系如图 8‑1所示. ...

  4. [ASP.NET]Web网站与Web应用程序区别

    [ASP.NET]Web网站与Web应用程序区别   本文链接:https://blog.csdn.net/a954553391/article/details/86403521 前言:在项目开发中, ...

  5. Web网站与Web应用程序区别

    创建时的目录结构不同. WEB应用程序一般处理程序有命名空间,而网站中的没有.(因为应用程序最后要编译成一个DLL文件,会产生命名冲突,而网站每个页面会编译成每一个的DLL,不会文件内产生全名冲突). ...

  6. 菜鸟疑问之新建网站与新建web应用程序区别

    学习asp.net一定少不了这困惑:新建网站与新建web应用程序有什么区别? 新建web应用程序 新建网站 呵呵,其实从名字看一个是webApplication,一个是webSite.名字不同罢了? ...

  7. 新建网站与新建Asp.Net Web 应用程序的区别

    .net网站和应用程序区别,网站是动态执行的不用编译,他只依赖于自己的文档本身,甚至你用aspx里直接写jsp代码都可以,其实网站可以说只是在.net平台中打开的文档,相当于最初的记事本编码,他并不需 ...

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

    由于生成Web应用程序的文件非常大,100M左右,上传到香港太慢,对于运维工作很不现实, 所以只能改用单个源代码文件上传方式,也就是Web网站方式,但VS2010中只提供Web网站转Web应用程序功能 ...

  9. VS2010新建Web网站与新建Web应用程序的区别

    在Visual Studio 2010中,除了可以使用“创建Web应用程序”的方式来构建自己的Web项目之外,还可以通过创建“Web网站”的方式来构建Web项其中,Web网站的创建方法:打开Visua ...

随机推荐

  1. linux备忘命令

    1,安装vim以后把vim中的tab键设置为4个空格 vim ~/.vimrc一下,如果没有会创建新的, 然后添加下面两行: set ts=4 set expandtab 如果第二行内容是noexpa ...

  2. python的类定义与实例化

    理解类属性和实例属性: 直接在类里面定义的变量叫类属性,类属性是公有的,每个类实例化就自动拥有类的属性,且实例化对象的这个属性的初始地址指向类属性的地址 如果直接给实例化对象的属性赋值这样会改变该属性 ...

  3. 7_5 困难的串(UVa129)<回溯法:避免无用判断>

    “超级氪因素大赛”(译注:英国的一档电视心智竞答节目)的主办方雇你来对付那些足智多谋的参赛选手.在比赛的一个环节中,节目主持人将念出一长串的字母来考验选手的记忆能力.因为许多选手都是分析字串模式的高手 ...

  4. RPA_播放语音

    验证码识别 from rpa.captcha.captcha import Captcha c = Captcha() log.info(tmp_file_path) captcha_result = ...

  5. C语言对两个浮点数进行比较的方法

    C语言对两个浮点数进行比较: C语言用"=="来比较两个浮点数,返回值完全是不确定的.  因此只能定义一个精度来确定是否相等: if(fabs(a-b) < 0.000000 ...

  6. js加密(八)新浪微博登录

    1. url: https://weibo.com/ 2. target: 登录 3. 分析.由于需要填写验证码,本篇只分析破解用户名和密码加密部分,不做验证码识别. 3.1 老规矩,F12,随便输入 ...

  7. JS高级---构造函数通过原型添加方法,原型的作用: 共享数据, 节省内存空间

    JS高级---构造函数,通过原型添加方法,原型的作用: 共享数据, 节省内存空间 构造函数 //构造函数 function Person(sex, age) { this.sex = sex; thi ...

  8. java web编写四则运算

    首先先画出一个表 <%@ page language="java" contentType="text/html; charset=UTF-8" page ...

  9. Blockchain technology and Application

    BTC-密码学原理 比特币本质:crypto currency[加密货币] 比特币用到的两个功能: 1.哈希 crypto graphic hash function 2.签名(非对称加密) 哈希cr ...

  10. 高次arccos积分

    \[\Large\displaystyle \int_0^{1} \frac{\arccos^4 \left(x^2\right)}{\sqrt{1-x^2}}\,\mathrm{d}x\] \(\L ...