Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

iis 7 - Running an ASP.NET MVC app from a virtual directory in IIS7

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...