Url.Action for mvc3 application hosted in a sub directory
Asked Answered
P

4

8

I have deployed a mvc3 application in web. How can i add Virtual directory name in Url.Action() method ?

for eg : my application is in mydomain.com\app

now when i do

Url.Action returns action="/Home/Create" but what i want is action = "/app/Home/Create".

What should be done ?

Ptyalism answered 21/2, 2013 at 13:29 Comment(0)
R
8

You shouldn't need to do that. If your application is properly deployed in IIS inside a virtual directory (say App) then the Url.Action("Create", "Home") helper will generate /app/home/Create which is the correct url.

Recovery answered 21/2, 2013 at 14:18 Comment(1)
I second this, I host multiple apps in virtual directory and never had this issue.Pournaras
A
1

Map a route (NOTE: this route has to appear BEFORE the default route)

        context.MapRoute(
            name: "app",
            url: "app/{controller}/{action}/{id}",
            defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional }
        );

Then use Url.Action like this (should give you /app):

@Url.Action("Index", "Test")

You can find routes in your Global.asax.cs file.

Ane answered 21/2, 2013 at 13:50 Comment(0)
V
0

It appears what you are trying to do is create an AREA. MVC supports the use of Area to further organize the Controllers and Actions in your application.

Please see this MSDN arcticle for more info: http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

Valuable answered 21/2, 2013 at 21:9 Comment(0)
P
0

Finally I am using Url.Content("~/Home/Create") which returns the whole URL whether hosted on main or sub directory.

Ptyalism answered 13/4, 2013 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.