如何将 ASP.NET 网站转换为 ASP.NET Web 应用程序 [英] How to convert ASP.NET website to ASP.NET web application

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

问题描述

我有一个 ASP.NET 3.5 网站(visual studio 行话),但该网站仍在继续增长,并且在其他方​​面看起来相当牛仔.我希望看到它被转换成一个 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?

推荐答案

好吧,事实证明网站"不存在转换为网络应用程序"选项.转换为 Web 应用程序"选项仅适用于Web 应用程序"!!!

[强调我的]

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

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

  • 向您的 VS 2008 解决方案添加一个新的Web 应用程序"(文件->添加->新建项目->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).

然后,您将旧网站"中的所有文件复制到您的新网站"中创建了网络应用程序",以及覆盖在其中创建的任何文件默认

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

下一步最难看,需要手动"添加引用在您的网站"到新的网站"应用程序".我以为是 VS 2008PowerCommands 玩具会为我做这个因为它确实复制了其他人的引用项目类型,但它没有.你有自己做,手动,和在这一步你必须谨慎如果您有多个版本的相同的程序集(如我的 AJAXToolkit 中的case) 或同时具有 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 解决方案资源管理器,对单击它,然后您将找到选项转换为 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 文件.修复非设计师问题和单击转换为 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"文件夹,尤其是那些没有命名空间.这些可能是一个很大的陷阱.我们有两个问题相同的扩展方法重载没有命名空间的静态类,一个扩展日期时间?(可空)并调用另一个重载扩展 DateTime 本身.调用其他重载作为扩展方法通过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".这个新名字听起来丑陋,但不要重命名它.在网络应用程序"模型,所有代码将在一个程序集.在运行时,网络服务器不知道什么网络您正在使用的项目类型.它确实获取Ap​​p_Code"文件夹中的所有代码,然后为其创建一个新程序集.这个方式,如果您在名为的文件夹中有代码App_Code",你最终会得到 RUNTIME相同类型的编译错误存在于两个程序集中,一个由 VS 创建,而由 VS 创建的IIS/ASP.NET 开发服务器.到避免那个.离开Old_App_Code"同名,或重命名为除了:App_Code".不要将任何代码放在这样的App_Code"中文件夹,最好没有在您的网络"中具有此类名称的文件夹应用程序".

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天全站免登陆