asp.net-mvc-3 - URL 或 Domain/AppName 中的重复域

标签 asp.net-mvc-3

我确定这是一个简单的问题,但我注意到当我托管(GoDaddy 上的共享主机)网站时,URL 会重复应用程序名称。

例如,我有 http://makedifferences.org ,如果我去这个很好,但如果我点击一个链接,它会把我带到http://makedifferences.org/makedifferences/ ...

不仅仅是这个网站,它是我在 GoDaddy 上的所有网站,我认为我在其他地方托管的网站上可能是一样的,但我现在无法检查它们。

我没有使用 web deploy 来部署它,因为我的第一个想法是它必须做 IIS。我的猜测是它必须是发布设置中的一个设置,但我玩弄了它们,似乎无法让它消失。

任何意见,将不胜感激。
谢谢,
加勒特

更新

这显然不是 mvc 的事情,因为我检查了我在 dotnet-host.com 上托管的站点并且它没有这个问题。所以我想这与我在 Godaddy 的设置有关。

我已经删除了该文件夹并设置了一个虚拟文件夹,但这并没有解决问题。

我有多个站点通过它们托管,我的域名 A 记录是我所有站点的专用 IP,然后在主机的域管理中,我将域名指向站点所在的文件夹。

我认为这是正确的方法,但我不确定。

现在我对它有了更多的了解,再次重申我的问题,如果我输入 http://makedifferences.org/Charities/Details/3页面加载,一切都很完美。但是如果我点击主页上的链接去那里,网址是 http://makedifferences.org/makedifferences/Charities/Details/3

谢谢为什么我认为这是 Visual Studio 中的设置。

最佳答案

有两件事会导致这种行为。

  • 您的应用程序安装在共享主机的文件夹而不是根目录中。
  • 您的 DNS 设置将域名指向此文件夹。

  • 我想您在共享主机中托管多个网站。

    要解决这个问题,您需要进入 IIS 设置并将这些文件夹设置为虚拟目录.....或者为每个网站创建一个....然后在该文件夹中安装您的应用程序。

    更新

    This is actually not an issue related to GoDaddy shared hosting at all but an issue with hosting an ASP.NET MVC site in a virtual directory. When you use the shared hosting provided by GoDaddy you get a root folder and limitless subfolders, each of which can be its own domain, by way of virtual directory. Unfortunately, MVC’s routing engine produces URLs that will include the virtual directory name appended to the domain name.

    For example, let’s say you have a domain named http://www.example.com and your folder/virtual directory name is /File. If you take the MVC template project without making any modifications and upload it to your folder and then go to your url everything will look fine. You will notice the ‘Home’ and ‘About’ tabs at the top right of the page. When you click on the ‘About’ tab, since it is routed to the Home controller’s About action, you would rightly expect the URL to be www.example.com/Home/About. What you will see, though, is that the URL generated by the ActionLink method includes the name of the virtual directory. Therefore, the URL will be www.example.com/File/Home/About.



    要解决此问题,请将以下代码添加到您的 Web.config 的 system.webServer元素
    <rewrite>
        <rules>
            <rule name="Remove Virtual Directory">
                <match url=".*" />
                <action type="Rewrite" url="{R:0}" />
            </rule>
        </rules>
    </rewrite>
    

    HERE 寻求解决方案

    祝你好运:-)

    关于asp.net-mvc-3 - URL 或 Domain/AppName 中的重复域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8959882/

    相关文章:

    javascript - 使用 jquery 加载和插入 ASP.NET 分部 View

    jquery - ASP.NET MVC 3 LoadingElementDuration 不起作用?

    asp.net-mvc-3 - MVC3 - 将数据传递到模型之外的部分 View

    asp.net-mvc-3 - 如何让 MVC3 给出更少的错误信息

    css - MVC3 中的 WebGrid 与 RAZOR 对齐

    asp.net - 使用 session 包装器代替对 session 变量的直接调用

    c# - MVC3 Json 绑定(bind)错误?

    asp.net-mvc-3 - ASP.NET AJAX.BeginForm 发送多个请求

    asp.net-mvc - 为集合中的每个项目使用 DisplayTemplate(带有 DisplayFor)

    c# - 在 ASP.NET MVC 中,我应该重定向到错误页面还是只返回错误 View ?