1

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(), "~");

2
  • Can you post your route config? Commented Jul 24, 2013 at 16:47
  • I'm a little confused about what you're actually trying to do here. You want to change the url of your app on the server? You want to change url of your app on the dev environment? You want to generate the right urls for each? That's what Url.Action already does... I don't really understand what your problem is. Also, fyi, it's not ~/ucms/User unless you have misconfigured things, it's ~/User = /ucms/User.. ~ means application root relative, and the application root is /ucms. Commented Jul 24, 2013 at 18:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your reply. I am looking for a generic one, for e.g. if virtual directory is different in other environment, the database values need to be changed again to ~/someothername/user. Instead it should be ~/user in database and application needs to manage different configurations.
I'm confused as to why you're having issues in the first place. The tilde (~) means "home directory", which in the case of a website hosted at a virtual path, will translate into the virtual path, i.e. "/ucms" in this case. That's the whole point of using the tilde. Otherwise, you'd just store the absolute path. I'm thinking however you're actually using this stored value is the problem, not the value being stored.
@ChrisPratt, I am sorry for the confusion. I've stored the url in the data table as "~/user" for authorization and site.map checks if the url is configured in database and shows up accordingly. In production, since it is "~/ucms/user" all menu items fail to show up. I was thinking if I include ucms in the database , it might lack flexibility if the configuration is again changed. So, wanted to have the variable part managed by application and controllername/viewname in the database.
That was my point. In production your URL shouldn't be "~/ucms/user" but rather "/ucms/user". The "ucms" bit is the virtual path that the ~ should be replaced with. In development, you would have no virtual path, so the ~ is replaced with root ("/") and you end up with "/user", while in production it is replaced with the virtual path ("ucms") and you end up with "/ucms/user". The point of the ~ is to make the URL work relative to the site's main URL, whatever that is.
@ChrisPratt, is it better to have "~/user" in database and then use "~"+Url.Action("Index","User").Replace("/ucms", "") having "/ucms" value configurable in web.config. Any thoughts ?
|

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.