5

very weird problem, I spent hours but not be able to find what exactly the problem is. I have some code as follows:

    public static string AbsoluteAction(this UrlHelper urlHelper, string actionName, string controllerName, object routeValues)
    {
        return ResolveUrl(urlHelper, urlHelper.Action(actionName, controllerName, routeValues));
    }

    private static string ResolveUrl(UrlHelper urlHelper, string relativeUrl)
    {
        return new Uri(GetRequestUri(urlHelper), relativeUrl).AbsoluteUri;
    }

    private static Uri GetRequestUri(UrlHelper urlHelper)
    {
        return urlHelper.RequestContext.HttpContext.Request.Url;
    }

When using string.Empty as routeValues, "urlHelper.Action(actionName, controllerName, routeValues)" works well on my local dev machine. (Windows 7, IIS 7.5, .Net 4.0, MVC3) It returns correct url.

But it returns empty string on our continuous integration server. (Windows server 2008, IIS 7.0, .Net 4.0, MVC3)

This is the route configuration:
routes.MapRoute(
"MyRouteName",
"getaddresses/{postcode}/",
new { controller = "Address", action = "GetAddresses", postcode = string.Empty },
new { httpMethod = new HttpMethodConstraint("GET") }, new[] { "My.Package.Controllers" });

If I use some string rather than string.Empty as RouteValues, it works well on both machines.

It seems that the issue is caused by different configurations or different version of tools or frameworks on dev machine and CI machine. Does anybody can help?

For you to better understand this issue, this is the context: The team is using .Net 3.5, Visual Studio 2010, MVC2. I upgraded them to .Net 4.0, Visual Studio 2012, MVC3. Everything is fine on my local dev machine. I installed .Net 4.0 and MVC3 on CI server (Not same installation files to dev machine, because they are installed along with visual studio). The website is running well on CI server. The only problem is that one smoke test is failed, which expects "localhost/getaddresses" is returned when calling AbsoluteAction("action name", "controller name", new {postcode=string.Empty} ), but it is actually "localhost"

Hope I have well described the issue. : )

Many thanks!

0 Answers0