Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have this controller action that is called from and script, works fine in visualstudio adds the item ok, but when add to iis server as an app with a virtual dir looks like "Store/ShoppingCart/AddToCart" and should only be "/ShoppingCart/AddToCart" is there a way to remove the app dir name "Store"? thanks in advance

public ActionResult AddToCart(int id, int qty)
            // Retrieve the item from the database

            var addedItem = storeDB.Items
                .Single(item => item.ID == id);

            // Add it to the shopping cart

            var cart = ShoppingCart.GetCart(this.HttpContext);
            int count = 0;
            int ct = 0;
            while (ct < qty)
                count = cart.AddToCart(addedItem);

* script
$(function () {

$('.AddLink').click(function () {
var quantity = $(this).closest('.product').find('.qty-input').val();
var recordToAdd = $(this).data('id'); // correct usage to access data- attributes
var url = '@Url.("AddToCart", "ShoppingCart")';

if (recordToAdd != '') { // not sure why you need this (why would it ever be null?)

$.post( url, { "id": recordToAdd, "qty": quantity }, function (data) {


F-ES Sitecore 10-Jul-15 3:24am    
That's how virtual directories work. If you don't want a prefix on your urls don't use a VD.

1. Open IIS Manager.
2. In the Connections pane, expand the Sites node in the tree, and then click to select the site for which you want to delete a virtual directory.
3. In the Actions pane, click View Virtual Directories.
4. On the Virtual Directories page, select the virtual directory that you want to remove.
5. In the Actions pane, click Remove and then Yes.
Share this answer
Gabriel Leon Leyva 9-Jul-15 12:22pm    
but deleting the virtual directory I also remove the app or not? Do I have to install the app in an stand alone server so it get root access? or is there a url config to remove the app name (virtual dir) from the route.

Thanks :-)
Dharmesh .S. Patil 10-Jul-15 2:14am    
Removing a virtual directory in IIS does not delete the physical content from the Windows file system; it removes the relationship of the content as a virtual directory under an application.
Gabriel Leon Leyva 10-Jul-15 13:44pm    
Ok there is no virtual Directory, when you create an app iis manager ask for an alias and physical path, is that alias what is cousing problems, if the app is in the root of server works fine, but is I create an app between root its when the script stops working. the scripts calls the action /ShoppingCart/AddToCart in server's root.
but when I create an app by name "Store" the action changes to /Store/ShoppinCart/AddToCart and stops working.
For more Information you can follow this link :[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900