Skip to main content
 首页 » 编程设计

c#之ASPX 背景图片在源代码中显示但在网页中不显示

2024年02月23日16freeliver54

我正在使用 VS2005 C#。

我有一个使用 CSS 背景图片的登录页面。

在我修改我的 web.config 以适应 AD 身份验证后,背景图像不再显示。

在源代码中查看时,我能够看到背景图像,但是当登录页面在浏览器中查看时,背景是纯白色的。

下面是我的Login.aspx、loginCSS.css 和Web.config 的代码片段:

登录.aspx:


<head runat="server"><link rel="stylesheet" type="text/css" href="loginCSS.css" /> 
    <title>Login</title> 
<script language="javascript" type="text/javascript"> 
</script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div  align="center"> 
    <asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8"  
            BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"  
            Font-Size="Small" ForeColor="#333333" Height="130px"  
            Width="303px"> 
          <TextBoxStyle Font-Size="Small" /> 
          <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"  
              BorderWidth="1px" Font-Names="Verdana" Font-Size="Small" ForeColor="#284775" /> 
          <InstructionTextStyle Font-Italic="True" ForeColor="Black" /> 
          <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="Small"  
              ForeColor="White" /> 
        </asp:Login> 
 
</div> 
    </form> 
</body> 
</html> 

登录CSS.css


body  
{ 
    background-image:url('images/loginbackground.png'); 
    background-repeat:no-repeat; 
    background-attachment:fixed; 
} 

网络配置:


<authentication mode="Forms"> 
            <forms name=".ADAuthCookie" timeout="10" loginUrl="Login.aspx" defaultUrl="~/Common/Default.aspx"> 
            </forms> 
        </authentication> 

我可以知道出了什么问题吗?有没有更好的方法在我的登录表单中显示背景图片?

请您参考如下方法:

听起来您可能需要对您的 CSS 或图像文件进行身份验证。

尝试添加

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

这将使您无需登录即可获得任何人检索您的 css/图像的权限