asp.net - 注销后 CSS 渲染问题

标签 asp.net html css visual-studio

我有一个主母版页和三个从它继承的母版页;我的网站根据用户的状态(注销、没有管理员权限登录、使用管理员权限登录)更改母版页,以便适本地更改侧面菜单。

当我登录时,母版页 normaluser.master 和 admin.master 工作得很好。

当我注销时,loggedout.master 无法渲染样式表中的任何 css,将我漂亮的侧面菜单变成带下划线的蓝色链接列表,并删除所有标题样式。

MasterPage.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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 id="Head1" runat="server">
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color: rgb(231, 231, 255);height:100%;margin:0px;padding:0px">
    <form id="form1" runat="server">
    <div style="background-color:rgb(74, 60, 140);color: rgb(247, 247, 247);height:20%">
        <div style='width:7%;display:inline-block;border:none;padding:0px;padding-left:2px'>
            <img src="Images/globe2.png" style="height:100px;vertical-align:middle"/>
        </div>
        <div style='display:inline-block;vertical-align:middle;'>
            <span style='font-size:36pt;padding-left:10px;font-family:Century,inherit'> Welcome To MeetSmart: </span><span style="font-size:16pt;font-style:italic"> Your smarter meeting solution</span>
        </div>
    </div>
    <div style="height:80%">
        <div style='width:15%;height:100%;display:inline-block;text-align:center;margin-top:10px;padding:0px;'>
            <asp:ContentPlaceHolder id="Menu" runat="server">

            </asp:ContentPlaceHolder>

        </div>
        <div style='display:inline-block;margin:0px;padding-left:10px;padding-top:20px;border:2px solid purple;width:75%;height:100%;vertical-align:top'>
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

            </asp:ContentPlaceHolder>
        </div>
    </div>
    </form>
</body>
</html>

普通用户.master:

<%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="normaluser.master.cs" Inherits="normaluser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>
<asp:ContentPlaceHolder id="title" runat="server">
</asp:ContentPlaceHolder>
</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" Runat="Server">
        <div class='menuItem'> <a href="Schedule.aspx" class='menuItem'>My Schedule </a></div>
        <div class='menuItem'> <a href="MyProfile.aspx" class='menuItem'>My Profile </a></div>
        <div class='menuItem'> <a href="DocManagerUser.aspx" class='menuItem'>Document Center </a></div>
        <div class='menuItem'> <a href="Directory.aspx" class='menuItem'>Directory</a></div>
        <div class='menuItem'> <a href="Logout.aspx" class='menuItem'>Log out </a></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ContentPlaceHolder id="mainContent" runat="server">

    </asp:ContentPlaceHolder>
</asp:Content>

注销.master:

<%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="LoggedOut.master.cs" Inherits="LoggedOut" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link runat="server" href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <title>

    <asp:ContentPlaceHolder id="title" runat="server">
    </asp:ContentPlaceHolder>
    </title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" Runat="Server">
    <div class='menuItem'><a href="Login.aspx" class='menuItem'>Log In </a><br /></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ContentPlaceHolder id="mainContent" runat="server">
    </asp:ContentPlaceHolder>
</asp:Content>

无论有没有“runat=server”,loggedout 中的样式表链接都不执行任何操作;添加这是我尝试解决它的一种方法。所有母版页和样式表都位于同一文件夹中。

最佳答案

考虑到您的描述,看起来您的 CSS 位于受身份验证保护的目录中。为了使 CSS 和脚本在登录和其他未经身份验证的页面上可用,您需要使它们在身份验证之外可用。

为此,您可以将这些 CSS 和脚本等添加到目录(例如根目录上的公共(public)文件夹),并使用 web.config 中的 location 元素为每个人提供对这些目录的访问权限。这不会损害您的安全。

<configuration>
   <location path="Public">
      <system.web>
         <authorization>
            <allow users="*"/>
         </authorization>
      </system.web>
   </location>
</configuration>

关于asp.net - 注销后 CSS 渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5789134/

相关文章:

.net - 计算 ASP.net/c# 中的 session 数

c# - 动态加载用户控件 - 回发问题

c# - 在 ASP.Net 中创建 razor 动态 html 表

javascript - 表中的 jQuery slideDown 和 SlideUp 看起来不正确

html - 使用 bootstrap 4 flexbox 垂直对齐多行

css - 父级鼠标悬停时可见隐藏的子 div

c# - 如何获取我的 Facebook 好友列表?

javascript - 保存暗模式状态 html/css/js

javascript - jQuery 隐藏表格行

html - 如何在没有 CSS 的情况下从表情符号中删除颜色