VS2008中的ASP .Net MVC - 发布的版本看起来不同

时间:2022-01-18 15:03:05

When I run my MVC application through Visual Studio 2008, the website looks fine with regards to the styling, images, etc.

当我通过Visual Studio 2008运行我的MVC应用程序时,该网站在样式,图像等方面看起来很好。

But if I publish this build to a folder and use IIS to view it, the styling is all over place, and images are not right.

但是,如果我将此版本发布到一个文件夹并使用IIS来查看它,那么样式就会到位,并且图像不正确。

Initially, I thought this was some error on my behalf with regards to the style sheet, but I am using only a slightly modified version of the stylesheet that came out-of-the-box with the MVC template.

最初,我认为这对于样式表来说代表了我的一些错误,但我只使用了与MVC模板开箱即用的样式表的略微修改版本。

Am I doing something wrong with regards to publishing the site, or with the CSS sheet?

我是否在发布网站或使用CSS表单方面做错了什么?

Kind regards,

Brett

3 个解决方案

#1


The most likely culprit is that your paths are relative to the root of the site and you are publishing in a folder that isn't at the root. You'll want to change your URLs in your CSS to make them relative to the CSS file and in your mark up to use Url.Content so that the URLs are translated dynamically.

最可能的罪魁祸首是您的路径是相对于站点的根目录而您是在不在根目录的文件夹中发布。您需要更改CSS中的网址,使其与CSS文件相关,并在标记中使用Url.Content,以便动态转换网址。

<img src='<%= Url.Content( "~/Content/images/image.png" ) %>' alt="" />

#2


I had nearly the exact same issue, then remembered my URLs. If you view the source in your IIS version, you should be able to see that the URL's are incorrect when pointing to the CSS files etc...

我几乎完全相同的问题,然后记住了我的网址。如果您在IIS版本中查看源代码,您应该能够在指向CSS文件等时看到URL不正确...

I replaced all of the CSS and JS calls in my master with the helper methods eg:

我用助手方法替换了我主人的所有CSS和JS调用,例如:

<%= Html.RegisterCSS("site.css") %>
<%= Html.RegisterScript("jquery-1.3.2.min.js") %>

Hope this helps...

希望这可以帮助...


Edit: Ahh, yep, I've created a helper to "help" me out. So, I've got the following code in a helper.

编辑:啊,是的,我已经创建了一个帮助我“帮助”我的帮手。所以,我在帮助器中有以下代码。

public static string RegisterScript(this System.Web.Mvc.HtmlHelper helper, string scriptFileName)
    {
        string scriptRoot = VirtualPathUtility.ToAbsolute("~/Scripts");
        string scriptFormat = "<script src=\"{0}/{1}\" type=\"text/javascript\"></script>\r\n";
        return string.Format(scriptFormat, scriptRoot, scriptFileName);
    }
    public static string RegisterCSS(this System.Web.Mvc.HtmlHelper helper, string FileName)
    {
        //get the directory where the scripts are
        string Root = VirtualPathUtility.ToAbsolute("~/Content");
        string Format = "<link href=\"{0}/{1}?{2}\" rel=\"stylesheet\" type=\"text/css\" />";
        return string.Format(Format, Root, FileName, DateTime.Now.ToString("hhmmss"));
    }

And I've had a "gotcha" where IE8 was displaying in IE7 mode. This caused me a headache until a colleague pointed it out... I haven't got IE8 here but I think it's in the developer tools section.

我有一个IE8在IE7模式下显示的“问题”。这让我很头疼,直到一位同事指出...我还没有IE8,但我认为这是在开发人员工具部分。

#3


This was entirely my fault!

这完全是我的错!

I used tags on my page to try to display tabular data - this rendered fine when I was running the project from within Visual Studio, but when I published the site, the CSS on the page appeared distorted on the page in Internet Explorer 7 and 8.

我在我的页面上使用了标签来尝试显示表格数据 - 当我从Visual Studio中运行项目时这很好,但是当我发布网站时,页面上的CSS在Internet Explorer 7和8中的页面上显示失真。

However, when I viewed the same published build in Firefox 3, the website appeared to render correctly on the page...! Strange, I know.

但是,当我在Firefox 3中查看相同的已发布版本时,该网站似乎在页面上正确呈现......!奇怪,我知道。

I did try to correct the CSS to fix the parts that didn't render correctly in Internet Explorer, but ended up removing the tags entirely due to time, and brought in the tags instead, much to my dismay!

我确实尝试纠正CSS以修复在Internet Explorer中无法正确呈现的部分,但最终由于时间的原因完全删除了标记,而是引入了标记,这让我感到非常沮丧!

#1


The most likely culprit is that your paths are relative to the root of the site and you are publishing in a folder that isn't at the root. You'll want to change your URLs in your CSS to make them relative to the CSS file and in your mark up to use Url.Content so that the URLs are translated dynamically.

最可能的罪魁祸首是您的路径是相对于站点的根目录而您是在不在根目录的文件夹中发布。您需要更改CSS中的网址,使其与CSS文件相关,并在标记中使用Url.Content,以便动态转换网址。

<img src='<%= Url.Content( "~/Content/images/image.png" ) %>' alt="" />

#2


I had nearly the exact same issue, then remembered my URLs. If you view the source in your IIS version, you should be able to see that the URL's are incorrect when pointing to the CSS files etc...

我几乎完全相同的问题,然后记住了我的网址。如果您在IIS版本中查看源代码,您应该能够在指向CSS文件等时看到URL不正确...

I replaced all of the CSS and JS calls in my master with the helper methods eg:

我用助手方法替换了我主人的所有CSS和JS调用,例如:

<%= Html.RegisterCSS("site.css") %>
<%= Html.RegisterScript("jquery-1.3.2.min.js") %>

Hope this helps...

希望这可以帮助...


Edit: Ahh, yep, I've created a helper to "help" me out. So, I've got the following code in a helper.

编辑:啊,是的,我已经创建了一个帮助我“帮助”我的帮手。所以,我在帮助器中有以下代码。

public static string RegisterScript(this System.Web.Mvc.HtmlHelper helper, string scriptFileName)
    {
        string scriptRoot = VirtualPathUtility.ToAbsolute("~/Scripts");
        string scriptFormat = "<script src=\"{0}/{1}\" type=\"text/javascript\"></script>\r\n";
        return string.Format(scriptFormat, scriptRoot, scriptFileName);
    }
    public static string RegisterCSS(this System.Web.Mvc.HtmlHelper helper, string FileName)
    {
        //get the directory where the scripts are
        string Root = VirtualPathUtility.ToAbsolute("~/Content");
        string Format = "<link href=\"{0}/{1}?{2}\" rel=\"stylesheet\" type=\"text/css\" />";
        return string.Format(Format, Root, FileName, DateTime.Now.ToString("hhmmss"));
    }

And I've had a "gotcha" where IE8 was displaying in IE7 mode. This caused me a headache until a colleague pointed it out... I haven't got IE8 here but I think it's in the developer tools section.

我有一个IE8在IE7模式下显示的“问题”。这让我很头疼,直到一位同事指出...我还没有IE8,但我认为这是在开发人员工具部分。

#3


This was entirely my fault!

这完全是我的错!

I used tags on my page to try to display tabular data - this rendered fine when I was running the project from within Visual Studio, but when I published the site, the CSS on the page appeared distorted on the page in Internet Explorer 7 and 8.

我在我的页面上使用了标签来尝试显示表格数据 - 当我从Visual Studio中运行项目时这很好,但是当我发布网站时,页面上的CSS在Internet Explorer 7和8中的页面上显示失真。

However, when I viewed the same published build in Firefox 3, the website appeared to render correctly on the page...! Strange, I know.

但是,当我在Firefox 3中查看相同的已发布版本时,该网站似乎在页面上正确呈现......!奇怪,我知道。

I did try to correct the CSS to fix the parts that didn't render correctly in Internet Explorer, but ended up removing the tags entirely due to time, and brought in the tags instead, much to my dismay!

我确实尝试纠正CSS以修复在Internet Explorer中无法正确呈现的部分,但最终由于时间的原因完全删除了标记,而是引入了标记,这让我感到非常沮丧!