如何转换ASP.NET网站到ASP.NET Web应用程序 [英] How To Convert ASP.NET Website to ASP.NET Web Application

查看:202
本文介绍了如何转换ASP.NET网站到ASP.NET Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 3.5的网站(Visual Studio的行话),但该网站的持续增长,并正在寻找除其他事项外,而cowboyish。我想看到这个被转换成一个Web应用程序(命名空间和所有)。

I have an ASP.NET 3.5 Website (visual studio lingo), but the site continues to grow and is looking rather cowboyish among other things. I'd like to see this get converted into a Web Application (namespaces and all).

这是东西,可以在Visual Studio中轻松完成?如果不是,是否有任何其他工具,有可能造成所有的命名空间,等自动的?

Is this something that can be easily done in Visual Studio? If not, are there any other tools out there that could create all of the namespaces, etc. automagically?

推荐答案

<一个href=\"http://weblogs.asp.net/meligy/archive/2008/08/03/converting-vs-2008-website-to-web-application.aspx\">Here是一个很好的演练:

好了,事实证明,选择转换为Web应用程序对网站不存在。选择转换为Web应用程序不仅存在于Web应用程序!!!!

Well, it turns out that the option "Convert to web application" does NOT exist for "websites". The option "Convert to web application" does exist only for "web applications" !!!!

[重点煤矿]

所以,这里的交易,做
  转换,您需要:

So, here's the deal, to do the conversion, you need to:


      
  • 添加一个新的Web应用程序,以你的VS 2008解决方案(文件 - >添加 - >新
      项目 - > C# - > Web的>的ASP.NET Web
      应用程序)。

  • Add a new "Web Application" to your VS 2008 solution (File->Add->New Project->C#->Web->ASP.NET Web Application).

之后,您在旧的网的所有文件复制到新
  创造了Web应用程序,并
  覆盖它创建的所有文件通过
  默认

Afterwards, you copy all the files in the old "website" to your newly created "web application", and override any files created in it by default

接下来的步骤是最丑的,你需要手动添加引用
  在网站,以新的网页
  申请。我认为2008年VS
  PowerCommands玩具会为我做这
  因为它从另一个副本引用
  项目类型,但事实并非如此。你有
  自己做,手动和
  你必须要在这一步谨慎
  如果你有多个版本
  相同的程序集(如在AJAXToolkit我
  情况下)或同时具有GAC组件
  和本地版左右。

The next step is the most ugly, you need to "manually" add the references in your "website" to the new "web application". I thought the VS 2008 PowerCommands toy would do this for me as it does copy references from other project types, but it didn't. You have to do it by yourself, manually, and you have to be cautious in this step if you have multiple versions of the same assembly (like AJAXToolkit in my case) or assemblies that have both GAC and local versions or so.

请重复最后一步,并试图打造的Web应用程序。
  你会不断收到类似的错误
  ......是未知的命名空间。你是
  缺少程序集引用? 制作
  确保你有没有那些除了中
  那些在这里'......被取代
  使用服务器控件的ID。在
  换句话说,不断添加引用
  和建设项目,直到只有
  存在由于错误
  缺少了.Designer.cs或.DESIGNER.VB
  文件。

Keep repeating the last step and trying to build the "web application". You'll keep getting errors like " '....' is unknown namespace. Are you missing an assembly reference? ". Make sure you have none of those except the ones where '....' is replaced by the IDs of the server controls you use. In other words, keep adding references and building the project until only the errors that exist because of missing .DESIGNER.CS or .DESIGNER.VB files.

之后,你可以在VS的Web应用程序根项目节点
  2008年Solution Explorer中,右
  点击它,然后你会发现
  选择转换为Web应用程序。
  这是什么选项执行实际上是
  进行小改动@Page
  页面和@Control指令和
  控制,并创建所需
  了.Designer.cs或.DESIGNER.VB文件。

Afterwards, go to the "web application" root project node in VS 2008 solution explorer, and right click it, then you WILL find the option "Convert to web application". What this option does is actually making small changes to the "@Page" and "@Control" directives of pages and controls, and creating the required .DESIGNER.CS or .DESIGNER.VB files.

再次尝试建设Web应用程序。如果出现错误,看什么
  引用可能会丢失和/或去
  单击转换为Web应用程序
  再次。有时候,如果有任何错误
  比那些缺少造成其他
  DESIGNER文件,而不是所有的
  页/控件将有那些
  为他们创造DESIGNER文件。
  固定非DESIGNER问题
  单击转换为Web应用程序
  再次应该为此做的工作。

Try building the "web application" again. If you get errors, see what references may be missing and/or go click the "Convert to web application" again. Sometimes, if there's any error other than those caused of missing DESIGNER files, not all the pages/controls will have those DESIGNER files created for them. Fixing the non DESIGNER problem and clicking "Convert to web application" again should do the job for this.

一旦你完成成功构建VS,你应该准备好了。
  开始测试您的Web应用程序。
  或者,您可以右键点击
  Web应用程序根项目节点
  VS 2008解决方案资源管理器,然后单击
  属性,然后转到标签网络
  设置Web应用程序到
  在IIS虚拟文件夹(你可以创建
  从那里新的虚拟目录
  VS)。如果你想使用IIS
  虚拟目录,老
  使用网站,您需要删除
  从IIS第一。

Once you are done successful VS build, you should be ready to go. Start testing your web application. Optionally, you can right click the "web application" root project node in VS 2008 Solution Explorer and click "Properties" then go to the tab "Web" to set the "web application" to a virtual folder in IIS (you can create new virtual directory from there in VS). If you want to use the IIS virtual directory that the old "website" used, you need to remove that from IIS first.

更​​新:在测试你的页面,最注重的类
  APP_ code的文件夹,特别是那些
  有没有命名空间。那些可以是一个大
  陷阱。我们有一个问题有两个
  扩展方法重载在同一
  静态类,没有命名空间,人们
  扩展日期时间? (可空)
  并调用另一个重载
  扩展日期时间本身。调用
  其他如超载扩展方法
  通过VS 2008的编译,给了我们
  编译错误只能在运行
  (对于IIS)。更改调用
  从调用它的其他超载
  扩展方法调用它作为
  正常的静态方法(只更换
  在同级别的号召,从来电
  其他类保持延伸
  方法调用)没有解决这个问题,但是
  显然,这不是因为它作为安全
  是在VS 2005特别是随着
  类没有命名空间。

Update: When testing your pages, pay MOST ATTENTION to classes in "App_Code" folder, especially those with NO NAMESPACE. Those can be a big trap. We had a problem with two extension method overloads in the same static class that had no namespace,one extends DateTime? (Nullable) and calls another overload that extends DateTime itself. Calling the other overload as extension method passed VS 2008 compilation and gave us a compilation error ONLY IN RUNTIME (With IIS). Changing the call to the other overload from calling it as extension method to calling it as normal static method (only changing the call in the same class, calls from other classes remained extension method calls) did solve this one, but clearly, it's not as safe as it used to be in VS 2005. Especially with classes with no namespaces.

UPDATE2:在转换过程中,VS 2008的重命名APP_ code按钮
  Old_App_ code。这个新名字听起来
  丑,但不要将其重命名。在
  在Web应用程序的模式,所有的code
  将在一个组件。在运行时,
  Web服务器不知道是什么网站
  您正在使用的项目类型。它确实
  采取一切code在APP_ code文件夹,
  创建一个新的组装它。这个
  这样,如果你有code文件夹命名
  APP_ code,你最终会使用运行时
  编译错误,同样类型的
  存在于两个组件,所述一个
  由VS创建,并且由创建的
  IIS / ASP.NET开发服务器。至
  避免这种情况。离开Old_App_ code
  使用相同的名称,或将其重命名为
  任何东西,除了:APP_ code。不要
  放在这样的APP_ code任何code
  文件夹和prefereably没有
  在您的网络这样的文件夹名称
  应用程序的说法。

Update2: During the conversion, VS 2008 renames your "App_Code" to "Old_App_Code". This new name sounds ugly, but DO NOT RENAME IT BACK. In the "web application" model, all code will be in one assembly. In runtime, the web server does not know what web project type you are using. It does take all code in "App_Code" folder and create a new assembly for it. This way, if you have code in folder named "App_Code", you'll end up with RUNTIME compilation errors that the same types exist in two assemblies, the one created by VS, and the one created by IIS / ASP.NET Development Server. To avoid that. leave the "Old_App_Code" with the same name, or rename it to ANYTHING EXCEPT: "App_Code". Do not place any code in such "App_Code" folder and prefereably do NOT have a folder with such name in your "web application" at all.

我知道这是由于过,但忘了
  现在我还没有使用网站的模式
  长:(

I know this since before but forgot it now as I have not used "website" model for long :(.

这篇关于如何转换ASP.NET网站到ASP.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆