0

I created a website where i passes url like this:

<base href="http://localhost:5423/" />

it all working fine for local.

but now i am deploying on host and problem arises here:

On the same index.vbhtml i have used menues like this:

<li><a class="home" href="Home/Index">Home</a></li>
<li class="wish"><a class="wishlist" href="Products/Index" id="wishlist-total">Products</a></li>
<li><a class="account" href="Home/Contact">Contact Us</a></li>

Now if i am trying with

HttpContext.Current.Request.Url

then its added root path everytime like if i click on Home,it shows correct first time:

http://192.168.1.100/Home/Index

But now if i am clicking again on same link,its adding Home again:

http://192.168.1.100/Home/Home/Index

what should be the solution for this.

Regards,

2
  • Where do you have MVC ? In MVC we usually construct links via helpers - like @Url.Action("ActionName","ControllerName") or via @ActionLink helper. Commented Apr 17, 2015 at 19:29
  • 2
    Thats because your missing the leading forward slash - "/Home/Index". But don't hard code your url's. Use the helpers so they are always generated correctly. Commented Apr 17, 2015 at 23:04

1 Answer 1

1

You can use Url.Action helper

<li><a class="home" href="@Url.Action("Index", "Home")">Home</a></li>
<li class="wish"><a class="wishlist" href="@Url.Action("Index", "Products")" id="wishlist-total">Products</a></li>
<li><a class="account" href="@Url.Action("Contact", "Home")">Contact Us</a></li>

Edit:

To generate absolute URLs try:

Url.Action("Index", "Home", null, Request.Url.Scheme)
Url.Action("Index", "Products", null, Request.Url.Scheme)
Url.Action("Contact", "Home", null, Request.Url.Scheme)
Sign up to request clarification or add additional context in comments.

2 Comments

Art thanks for your reply.i tried this earlier.See i am getting same issue with this.if i click on Home then url is like this: 192.168.1.100/Home/Index and after this if click on Contact or home multiple times then Home is added to url everytime like this: 192.168.1.100/Home/Home/Index what is the solution for this?
Hi Alex,i tried above edit part but its still not removing the 1st part. <li> <a href="@Url.Action("Index", "Home",System.DBNull.Value, Request.Url.Scheme)">Home</a></li> <li> <a href="@Url.Action("Index","Products",System.DBNull.Value,Request.Url.Scheme)">Products</a></li> if i am passing null then its giving me error.please suggest here.still i am getting wrong url: localhost:5423/Home/Home/Contact

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.