Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Action for mvc3 application hosted in a sub directory

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 ?

like image 361
Nitin Kabra Avatar asked Feb 21 '13 13:02

Nitin Kabra


2 Answers

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.

like image 145
Darin Dimitrov Avatar answered Sep 23 '22 07:09

Darin Dimitrov


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.

like image 43
Allov Avatar answered Sep 22 '22 07:09

Allov