What does Override application root URL really do?

倖福魔咒の 提交于 2020-01-02 00:19:08

问题


The only place on the entire internet I could find an explanation is on MSDN:

Specifies an alternative path for the application root URL. Use this option if the Web application root is not the root of your project.

From here I understood that "application root" is the path that retrieves when using tilde in ASP.NET. So I would expect that if I go to project's properties - Web - "Override application root" and specify another url then the tilde would map to that url.

But it doesn't. For example my web is on a virtual directory - http://localhost/WebApplication1 and on "Override application root" I try to specify http://localhost/WebApplication2 or http://localhost or http://WebApplication2 (which all exist on my local IIS). Now when I write

Response.Redirect("~/test2/login");

I expect it to redirect me to http://localhost/WebApplication2/test2/login. But instead it redirects me to http://localhost/WebApplication1/test2/login as if I didn't override the "application root".

So what does this feature really suppose to do? Or maybe it's not working because I'm missing something and didn't define it properly?


回答1:


Override application root URL doesn't change where the Application root is within your application. It changes the URL used to reach the application root. Because IIS does some hostname verification it's used to specify if you want to reach your application by a means other than localhost:[PORT].

For instance, if you override it to www.myapp.com you can then reach your application by adding this to your hosts file:

127.0.0.1     www.myapp.com

This might be especially useful if you're making your application available to a remote device (a virtual machine on your computer, or a mobile device on your network) because they would be unable to navigate to localhost as the application address.



来源:https://stackoverflow.com/questions/43888687/what-does-override-application-root-url-really-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!