我有一个主要的主页和三个从中继承的主页;我的网站根据用户的状态更改了主页(注销,登录时没有管理员权限,使用管理员权限登录),以便适当地更改侧边菜单。
当我登录时,母版页normaluser.master和admin.master工作正常。
当我退出时,loginout.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>
normaluser.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>
loggedout.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”,登出时的样式表链接什么都不做;添加这是我尝试解决它的一种方式。所有母版页和样式表都在同一个文件夹中。
答案 0 :(得分:3)
考虑到您的描述,看起来您的CSS位于受身份验证保护的目录中。为了让CSS和脚本在登录和其他未经过身份验证的页面上可用,您需要使它们在身份验证之外可用。
为此,您可以将这些CSS和脚本等添加到目录(例如root上的Public文件夹)中,并使用web.config中的location元素来提供对这些directoy的所有人的访问权限。这并没有妥协你的安全性。
<configuration>
<location path="Public">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>