Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP .NET MVC RedirectoToAction ignores the application where is located

I have a MVC application deployed in my server in a virtual directory like:

http://localhost/myapp/

Where "myapp" is the virtual directory

In my Login view, located in

"http://localhost/myapp/user/login", 

I redirect to the index using RedirectToAction("Index", "Home"), it seems the application try to redirect to

"http://localhost/home/index" 

instead of

"http://localhost/myapp/home/index".

The application works when it's located in the root of the IIS Web Site but doesn't work in the given situation.

It's there a way to configure the application root, that I missed?

Settings: Microsoft Visual Studio Express 2012 for Web, IIS 7 under Windows 7 , application pool ASP .NET v4.0

like image 244
Silvano Avatar asked Nov 02 '22 17:11

Silvano


1 Answers

I am 99% positive that doing:

return RedirectToAction("Index", "Home")

is application root relative meaning that it should redirect to the application you're in regardless of the virtual directory settings or where the application is located. I mean think of the nightmare otherwise that every time you move the app to a different virtual directory you need to update the global.asax or web.config file??? Ridiculous! We have the same setup that you have and we have no issues with "app hopping."

Are you sure that RedirectToAction is causing this? Could it be that you have something like:

@Url.Content("/Home/Index")

In that case you would experience this issue and you can easily fix this by doing:

@Url.Content("~/Home/Index")

~ symbol makes it application root relative...

like image 114
Marko Avatar answered Nov 11 '22 15:11

Marko