Search code examples
asp.net-mvc-3publish

Style not view when publish MVC3 to virtual directory IIS 7.5


When I publish web MVC3 to a virtual directory style of site not view. Link css file incorrect: /virtual directory/content/abc.css instead of /content/abc.css


Solution

  • change

    <link href="../../../../Content/Manager/SiteManager.css" rel="stylesheet" type="text/css" />
    

    to

    <link href="@Url.Content("~/Content/Manager/SiteManager.css")" rel="stylesheet" type="text/css" />
    

    ~ gives you the root.

    UrlHelper.Content converts virtual to the correct absolute path regardless of the directory structure that you have on dev, stage, prod,...