Sunny
Sunny

Reputation: 4809

Remove application name from url in ASP.NET MVC application

In my development environment

Url.Action("Index", "User") ---> /user

In production, the application is configured under a application named "ucms"

Url.Action("Index", "User") ---> /ucms/User

I have authorization based on the url i.e., /user, so it is failing in production environment. How do I fix this issue to remove ucms?

Edit Routes are default one's. FYI, I've upgraded application from mvc 3.0 to 4.0.

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");     
 routes.MapRoute(
                        "Default", // Route name
                        "{controller}/{action}/{id}", // URL with parameters
                        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

Edit I have figured out one way to do it, could anyone share thoughts on this.

Store the virtual path in web.config.

   <add key="appvirtualpath" value="~/ucms"/>

And while passing the url to the database layer, I would replace the virtual path will blank.

Url.Action("Index","User").Replace(ConfigurationManager.AppSettings["appvirtualpath"].ToString(), "~");

Upvotes: 1

Views: 3186

Answers (1)

Jeandre Pentz
Jeandre Pentz

Reputation: 1002

I solved this problem by adding a virtual path in development environment

Right click on project, properties, web and then virtual path.

I don't know if there is a way to configure it in the production environment

enter image description here

Upvotes: 1

Related Questions