I have an MVC3 Razor view which has a link that requires user login and its html is like this:
<a href="Home/Login?returnUrl=/myprojname/Product/Index">
and then an action method Login in homecontroller and a view. Which posts values to Logon action method.
inside the post action method I check if returnurl is not null then redirect to that URL. On local system it returns to this address
http://localhost:1235/myProjname/Product/Index
and works fine. But when I upload it to server (IIS 7), It returns to
http://domainname/myProjname/Product/Index
and gives 404 because there is no ‘myProjname’ there, If I remove the ‘myprojname’, it works with this url on live server
http://domainname/Product/Index
but for that I need to change href like this
<a href="Home/Login?returnUrl=/Product/Index">
In that case, It doesn’t work with local system with URL
http://localhost:1235/Product/Index
Please suggest solution
Are you serious?
Okay, we’ll i’ll play along.
The solution is to create links properly, not hard code them.
On a side note, you probably don’t need to pass
returnUrlto the action. Pull it back from theRequest.UrlReferrer.AbsoluteUriin the action method itself.Not meaning to sound rude, but I strongly suggest you head over to http://www.asp.net/mvc and have a read/watch before proceeding any further.