从 IIS7 中的虚拟目录运行 ASP.NET MVC 应用程序 [英] Running an ASP.NET MVC app from a virtual directory in IIS7

查看:43
本文介绍了从 IIS7 中的虚拟目录运行 ASP.NET MVC 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 IIS7 中的虚拟目录运行 MVC 应用程序?我在 ASP.NET MVC3 中构建了一个开源实用程序应用程序,想知道这是否是一个错误;可能是该站点无法从虚拟目录运行.

Is it possible to run an MVC application from a virtual directory in IIS7? I have built an open source utility app in ASP.NET MVC3 and wondering if that was a mistake; it likely is if the site cannot be run from a virtual directory.

如果从名为 /app 的虚拟目录运行,则采用简单的默认路由 /home/index,实际上将是/app/home 索引.哪种类型的路由搞砸了.

Take a simple default route of /home/index if running from a virtual directory named /app, will actually be /app/home index. Which kind of messes things up for routing.

我不希望用户必须更改路由并重新编译项目才能在虚拟目录中使用应用程序.有没有办法更改配置参数以指示应用程序的根文件夹是什么?

I don't want a user to have to change routes and recompile the project to use the app in a virtual directory. Is there a way to change a configuration parameter to indicate what the root folder of what the application is?

推荐答案

是否可以从 IIS7 中的虚拟目录运行 MVC 应用程序?

Is it possible to run an MVC application from a virtual directory in IIS7?

这不仅是可能的,而且是首选方式.

Not only that it is possible but it is the preferred way.

哪种情况会导致路由混乱.

Which kind of messes things up for routing.

如果您在处理 url 时使用 Html 助手,则不会.

Not if you use Html helpers when dealing with urls which will take care of this.

这是一个典型的例子,说明你不应该做的事情:

Here's a typical example of what you should never do:

<script type="text/javascript">
    $.ajax({
        url: '/home/index'
    });
</script>

这是应该如何完成的:

<script type="text/javascript">
    $.ajax({
        url: '@Url.Action("index", "home")'
    });
</script>

这是另一个你永远不应该做的事情的典型例子:

Here's another typical example of something that you should never do:

<a href="/home/index">Foo</a>

这应该是这样写的:

@Html.ActionLink("Foo", "Index", "Home")

这是另一个你不应该做的事情的例子:

Here's another example of something that you should never do:

<form action="/home/index" method="opst">

</form>

这应该是这样写的:

@using (Html.BeginForm("Index", "Home"))
{

}

我想你明白了.

这篇关于从 IIS7 中的虚拟目录运行 ASP.NET MVC 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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