route doesn't work at production environment

I have created following route

 routes.MapRoute("ThumbnailRoute",// Route name
           "Image/{action}/{session}/{parentId}/{fileName}/{ctype}/{thumbNailSize}", // URL with parameters
           new { controller = "Image", action = "GenerateThumbnail", session = "", parentId = "", fileName = "", ctype = "", thumbNailSize = 70 },  // Parameter defaults 
           new { controller = @"[^\.]*", action = @"[^\.]*" });

and my extension method returns a string like following which will be the src attribute of the img tag:

 return string.Format("/{0}/{1}/{2}/{3}/{4}/{5}/{6}", controller, action, session, parentId, fileName, ctype, thumbNailSize);

when I right click on the pages and choose properties for both dev and prod environments the src av img tag is same (http://localhost/Image/GenerateThumbnail/de-DE/121/0beac6da-7c09-4faf-ad4b-48326f9d337e.jpg/jpeg/70) only different is the domain name (localhost, www.domain.com) but the images de not appear on prod. thanks for your help

Answers


If the URLs look fine on the production version - perhaps the issue isn't with the routing, but rather with the code in the action method.

Have you checked what response you get from the browser when hitting the production URL?

What response do you get when your browse to http://www.domain.com/Image/GenerateThumbnail/de-DE/121/0beac6da-7c09-4faf-ad4b-48326f9d337e.jpg/jpeg/70?


Never hardcode urls as you did. Always use url helpers. The thing is that when you deploy your application in IIS there's a virtual directory name. So the correct url is the following:

http://foo.com/MyAppName/Image/GenerateThumbnail/de-DE/121/0beac6da-7c09-4faf-ad4b-48326f9d337e.jpg/jpeg/70

instead of:

http://foo.com/Image/GenerateThumbnail/de-DE/121/0beac6da-7c09-4faf-ad4b-48326f9d337e.jpg/jpeg/70

Since you have hardcoded the url you get 404.

So use the RouteUrl method to generate it which will take into account this virtual directory if any. Don't use any string formatting to build urls:

public ActionResult Index()
{
    string url = Url.RouteUrl("ThumbnailRoute", new
    {
        action = "GenerateThumbnail",
        controller = "Image",
        session = session,
        parentId = parentId,
        fileName = fileName,
        ctype = ctype,
        thumbNailSize = thumbNailSize
    });

    ...
}

Need Your Help

MM:hh:mm time with c ++

c++ time

So I haven't seen here or anywhere else a way to get only the month hours and minutes using <ctime> or other library.

Copy specific lines from cmd using a batch file

html windows batch-file cmd

I need to create a batch file that copies information from specific lines in command line (who are also generated by the same batch file using commands) to a text file for use in an html file.