ASP.NET MVC 3:已移动的应用程序到虚拟目录。我有什么改变? [英] ASP.NET MVC 3: Moved app into virtual directory. What do I have to change?

查看:154
本文介绍了ASP.NET MVC 3:已移动的应用程序到虚拟目录。我有什么改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我一直在一个MVC 3应用程序。我使用VS 2010的内置Web服务器。今天,由于种种原因,我被要求将其移动到一个虚拟目录,然后运行IIS 7下,还是我的开发PC上。

I have been working on an MVC 3 app. I was using VS 2010's built-in web server. Today, for various reasons, I was asked to move it into a virtual directory and run it under IIS 7, still on my development PC.

现在,它的网址是本地主机/ MyVirtualDirectory,而不是本地主机:12345?,我需要做什么改变,使路由工作,并在

Now that its URL is "localhost/MyVirtualDirectory" as opposed to "localhost:12345", what do I need to change to make routing work, and where?

我不使用任何原始的HTML锚标记或重定向,只是@ Html.ActionLink等。据我读过什么,如果我一直在做的事情的MVC方式,这种变化应该是透明的。

I'm not using any raw HTML anchor tags or redirects, just @Html.ActionLink and so on. According to what I've read, if I've been doing things the MVC way, this change should have been transparent.

但就在年初,认证后的重定向失败。在成功验证之后,它应该返回的结果

But right at the beginning, the post-authentication redirection fails. On successful authentication, it's supposed to return the result of

this.RedirectToAction("index", "Home")

您猜对了:而不是/ MyVirtualDirectory /家庭重定向去/家。这将失败。

You guessed it: instead of "/MyVirtualDirectory/Home" the redirection goes to "/Home". Which fails.

所以,缺了点什么,需要进行设置。这是什么?

So something is missing that needs to be set up. What is it?

感谢所有。

推荐答案

在IIS中,选择您的虚拟目录和转换为应用程序。此外,如果您使用的是在Global.asax中默认的路线图应该读的东西是这样的:

In IIS, choose your virtual directory and "Convert to Application." Also, if you are using the default route map in your Global.asax it should read something like this:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

推理:如果你把你的MVC应用程序在另一个应用程序的一个子目录,然后IIS将考虑其他的应用程序,而不是你的MVC应用程序的根目录的根目录。如果这是你想要的(不太可能)的行为,你需要修改你的Global.asax来考虑到这一点:

Reasoning: If you put your MVC application in a sub-directory of another application then IIS will consider the root of that other application instead of the root of your MVC application. If that is the behavior that you want (unlikely) then you need to modify your Global.asax to take that into account:

routes.MapRoute(
    "Default", // Route name
    "MyVirtualDirectory/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

这篇关于ASP.NET MVC 3:已移动的应用程序到虚拟目录。我有什么改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆