visual-studio 如何使 .net Web 应用程序作为 Visual Studio 中的根应用程序运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3338170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:15:19  来源:igfitidea点击:

How to make a .net web application run as the root application in Visual Studio

visual-studioiisweb-applicationsvirtual-directoryweb

提问by Vivian River

I've been converting some .net "Web Sites" to "Web Applications". This has been going along smoothly. One of the steps that I perform each time I do a conversion is I go to the web section of the project properties and set the virtual directory.

我一直在将一些 .net“网站”转换为“Web 应用程序”。这一直在顺利进行。每次进行转换时我执行的步骤之一是转到项目属性的 web 部分并设置虚拟目录。

So far, I've set up
-http://localhost/site1
-http://localhost/site2
-http://localhost/site3

到目前为止,我已经设置了
- http://localhost/site1
- http://localhost/site2
- http://localhost/site3

Finally, I've received the task of performing a Web Site -> Web Application conversion on the web site that resides on the root directory of our servers. However, if I specify http://localhost/as the virtual directory in Visual Studio, it results in an error. How do I go about converting the root web site to a web application project in Visual Studio?

最后,我接到了在位于我们服务器根目录的网站上执行网站 -> Web 应用程序转换的任务。但是,如果我在 Visual Studio 中将http://localhost/指定为虚拟目录,则会导致错误。如何在 Visual Studio 中将根网站转换为 Web 应用程序项目?

采纳答案by Vivian River

This feels like a KLUDGE, but I've found a way to do what I want.

这感觉就像一个 KLUDGE,但我已经找到了一种方法来做我想做的事。

First, open the Web settings tab of the project properties in Visual Studio. Set the virtual directory to http://localhost/someDirectory. You cannot set it to http://localhost/at this point as an error will result. Build your web site to the directory (on disk) where you want to host it from.

首先,在 Visual Studio 中打开项目属性的 Web 设置选项卡。将虚拟目录设置为http://localhost/someDirectory. 此时不能将其设置为http://localhost/,因为会导致错误。将您的网站构建到您想要托管它的目录(在磁盘上)。

Next, open the .proj file in notepad and find http://localhost/someDirectory; change it to http://localhost.

接下来,在记事本中打开 .proj 文件并找到http://localhost/someDirectory;将其更改为http://localhost.

Now, go in to your IIS settings and change the home directory of your web site to the directory where the web site is built on the disk.

现在,进入您的 IIS 设置并将您网站的主目录更改为该网站在磁盘上的构建目录。

Finally, open the project in Visual Studio again. Go to the web settings tab of the project properties and see that it is set to use the virtual directory http://localhost/.

最后,再次在 Visual Studio 中打开该项目。转到项目属性的 web 设置选项卡,查看它是否设置为使用虚拟目录http://localhost/

回答by Gage

To set your root directory go into IIS and right click the "Default Web Site"go to properties --> "Home Directory"and set "Local Path"to the directory of your root website. Then whenever you type http://localhost/it will point to that website.
I'm unsure about how this will effect your other sites though.

要设置您的根目录,请进入 IIS 并右键单击“默认网站”,然后转到属性 --> “主目录”并将“本地路径”设置为您的根网站目录。然后,每当您键入http://localhost/ 时,它都会指向该网站。
我不确定这将如何影响您的其他网站。

Let me know if this works.

让我知道这个是否奏效。