asp.net-mvc 更改项目 URL Visual Studio
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20978686/
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
Change Project URL Visual Studio
提问by William
I would like to be able to debug my ASP.NET MVC application on a domain other than localhost as well as any subdomains, in other words:
我希望能够在本地主机以外的域以及任何子域上调试我的 ASP.NET MVC 应用程序,换句话说:
http://domain.devhttp://*.domain.dev
http://domain.devhttp://*.domain.dev
I have tried the following:
我尝试了以下方法:
- Modify the Hosts file
- Add a Host record for *.domain.dev that returns 127.0.0.1
- Change the 'Project Url' in the project properties.
- 修改主机文件
- 为 *.domain.dev 添加返回 127.0.0.1 的主机记录
- 更改项目属性中的“项目 URL”。
However, nothing is working. When I start to debug I get a page that either says "Service Unavailable" or "Invalid URL".
但是,没有任何效果。当我开始调试时,我得到一个页面,上面写着“服务不可用”或“URL 无效”。
What am I missing?
我错过了什么?
p.s. I am using Visual Studio 2013
ps 我使用的是 Visual Studio 2013
回答by njfife
For Visual Studio 2015the steps in the above answers apply but the applicationhost.config file is in a new location. in your "solution" folder follow the path
对于Visual Studio 2015,上述答案中的步骤适用,但 applicationhost.config 文件位于新位置。在您的“解决方案”文件夹中,按照路径
\.vs\config
Within that folder you will see your applicationhost.configfile
在该文件夹中,您将看到您的applicationhost.config文件
Alternatively you could just search your solution folder for the .config file and find it that way.
或者,您可以在您的解决方案文件夹中搜索 .config 文件并以这种方式找到它。
I personally used the following configuration:
我个人使用了以下配置:
With the following in my hosts file:
在我的主机文件中包含以下内容:
127.0.0.1 jam.net
127.0.0.1 www.jam.net
And the following in my applicationhost.config file:
我的 applicationhost.config 文件中的以下内容:
<site name="JBN.Site" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Dev\Jam\shoppingcart\src\Web\JBN.Site" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:49707:" />
<binding protocol="http" bindingInformation="*:49707:localhost" />
</bindings>
</site>
Remember to run your instance of visual studio 2015 as an administrator!If you don't want to do this every time I recomend this:
请记住以管理员身份运行您的 Visual Studio 2015 实例!如果你不想每次我推荐这个时都这样做:
How to Run Visual Studio as Administrator by default
I hope this helps somebody, I had issues when trying to upgrade to visual studio 2015 and realized that none of my configurations were being carried over.
我希望这对某人有所帮助,我在尝试升级到 Visual Studio 2015 时遇到了问题,并意识到我的任何配置都没有被结转。
回答by dom
You need to actually create a new record for each subdomain in the hosts file. You can't use wildcards.
您实际上需要为 hosts 文件中的每个子域创建一个新记录。您不能使用通配符。
127.0.0.1 domain.dev
127.0.0.1 foo.domain.dev
127.0.0.1 bar.domain.dev
Although it seems that it can be done with some extra work, see this questionfor more details.
尽管似乎可以通过一些额外的工作来完成,但请参阅此问题以获取更多详细信息。
You also need to include the port number when accessing the URL. The browser would point to http://foo.domain.dev:0000, using the port number assigned in VS, of course.
您还需要在访问 URL 时包含端口号。当然,浏览器会http://foo.domain.dev:0000使用 VS 中分配的端口号指向。
If you are using the Visual Studio Development Server, that's all there is to it. If using IIS Express, it takes a bit more work.
如果您使用的是 Visual Studio 开发服务器,这就是全部。如果使用 IIS Express,则需要做更多的工作。


Then you need to make sure you have a record in the IIS applicationhost.config file :
然后你需要确保你在 IIS applicationhost.config 文件中有一个记录:
<site name="YourApplication" id="25">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Path\To\Your\App" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:2750:foo.domain.dev" />
</bindings>
</site>
Update
更新
<site name="DomainProject" id="18">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\William\Source" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:32939:domain.dev" />
<binding protocol="http" bindingInformation="*:32939:domain2.dev" />
</bindings>
</site>

