【问题标题】:CSS displaying in design view not at run timeCSS 显示在设计视图中而不是在运行时
【发布时间】:2012-10-29 15:37:54
【问题描述】:

我有一个具有菜单功能的基于母版页的网站。成功从 Style.css 文件中读取 CSS。我现在添加了一个单独的 Login.aspx 页面,该页面功能正常,但没有选择具有登录页面特定 css 的 Account.css 文件。我不希望登录页面引用母版页。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"      type="text/javascript"></script>
    <link href="Account.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
                 $('.grid_12').fadeIn(1750);
        });
    </script>
</head>

我将不胜感激,因为我已尝试以我能想到的各种方式引用 Account.css 文件路径:

href="./Account.css"
href="Account.css"
href="~/Account.css"

我现在已将 Login.aspx 页面和 Account.css 文件放在网站根目录的新登录文件夹中。

【问题讨论】:

  • 发布 CSS 参考的渲染 HTML。不知道为什么您甚至提到了母版页,因为它与问题完全无关(据我所知)。听起来您只是在从 ASPX 页面引用 CSS 文件时遇到问题。

标签: c# asp.net .net css visual-studio-2010


【解决方案1】:

您可能正在使用表单身份验证的区域。
如果是,那么您可以使用

 <location path="Account.css">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

里面

<appSettings></appSettings>

你也可以使用

<style type="text/css" src='<%= ResolveUrl("Account.css")%>'></script>

【讨论】:

  • 感谢大家的帮助,非常感谢。最后,我在登录文件夹中放置了一个 web.config 文件,允许匿名用户访问该文件夹中的所有资源。
【解决方案2】:

您似乎在 IIS 上的虚拟目录中托管您的网站。如果这样做,您的路径必须反映虚拟目录。

href="/virtualDir/Account.css"

要做到这一点,asp.net 使用ResolveClientUrl

href="<%= ResolveClientUrl("~/Account.css") %>"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多