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

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

问题描述

是否有可能运行在IIS7的虚拟目录MVC应用程序?我已经建立了ASP.NET MVC3,并想知道如果这是一个错误的开源工具的应用;它可能是,如果该网站不能从虚拟路径运行。

取一个简单的默认路由的 /家庭/指数如果从名为 /应用,实际上是/应用/主页索引一个虚拟目录中运行。哪种食堂的事情了路由。

我不希望用户不得不改变路线,并重新编译该项目使用的应用程序中的虚拟目录。有没有办法来改变一个配置参数来说明哪些应用是在根文件夹?


解决方案

  

是否有可能运行一个虚拟目录在IIS7 MVC应用程序?


不仅在于它是可能的,但它是preferred方式


  

这混乱的一种东西路由。


如果有,将照顾这处理的URL,当您使用HTML佣工。

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

 <脚本类型=文/ JavaScript的>
    $阿贾克斯({
        网址:'/家庭/索引
    });
< / SCRIPT>

和这里的如何应该是这样的:

 <脚本类型=文/ JavaScript的>
    $阿贾克斯({
        网址:'@ Url.Action(指数,家)
    });
< / SCRIPT>

下面的东西另一个典型的例子,你应该永远不会做:

 < A HREF =/家/指数>富< / A>

和这里的如何这应该这样写:

  @ Html.ActionLink(富,索引,家)

下面的东西另一个例子,你不应该做的:

 <形式的行动=/家/指数的方法=OPST>< /表及GT;

和这里的如何这应该这样写:

  @using(Html.BeginForm(指数,家))
{}

我想你明白了吧。

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.

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?

解决方案

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.

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>

and here's how this should be done:

<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>

and here's how this should be written:

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

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

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

</form>

and here's how this should be written:

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

}

I think you get the point.

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

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