请看下面的图片
如您所见,我有一个母版页Design.master
和它背后的代码,称为Design.master.cs
.
我只是想让我的页面重定向到dashboard.aspx
用户未登录时,但无论我尝试什么,我都无法做到。
我希望能够访问在redirect
后面的代码中设置的公共变量的值,并从Design.master
代码中访问它。
这样我就可以检查变量并将Response.redirect()
代码放在Design.master
页面中。
除非您知道如何让重定向从Design.master.cs
代码中工作?
请帮助:(这让我发疯了!
更新的图像
Design.master
代码:
<%@ Master Language="C#" CodeBehind="~/Design.master.cs" AutoEventWireup="true" %>
<%
Response.Redirect("default.aspx", true);
%>
<!DOCTYPE html>
<html>
<head>
<title>Portal</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="portal_script.js" type="text/javascript"></script>
</head>
<body>
<div id="main_wrapper">
<div id="header_top_wrapper">
<div id="header_top">
<img src="images/design/logo_small.png" id="logo_top" />
<a href="basket.aspx">
<div id="basket_top_link">
<div>Order Basket</div>
</div>
</a>
</div>
</div>
<div id="header_breadcrumb_wrapper">
<div id="header_breadcrumb"></div>
</div>
<div id="content_wrapper">
<div id="content">
<div id="side_menu">
<div id="customer_info">
<asp:ContentPlaceHolder id="CustomerInfo" runat="server">
</asp:ContentPlaceHolder>
</div>
<a href="dashboard.aspx"><div class="side_menu_item">
<div class="item_title">View Orders</div>
<div class="item_description">View your outstanding orders</div>
</div></a>
<a href="search.aspx"><div class="side_menu_item">
<div class="item_title">Product Search</div>
<div class="item_description">Search products and view stock levels</div>
</div></a>
<a href="search.aspx"><div class="side_menu_item">
<div class="item_title">Outstanding Complaints</div>
<div class="item_description">View status of complaints</div>
</div></a>
</div>
<div id="content_left">
<asp:ContentPlaceHolder id="Content" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</div>
<div id="footer_wrapper">
<div id="footer"><p></p></div>
</div>
</div>
</body>
</html>
Design.master.cs 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Design : System.Web.UI.MasterPage
{
public bool redirect = false;
protected override void OnInit(EventArgs e)
{
// Get the users session
SessionManager session = new SessionManager(HttpContext.Current);
// I've tried it here, and it won't redirect
// Response.Redirect("default.aspx");
redirect = true;
}
protected void Page_Load(object sender, EventArgs e)
{
// I've tried it here, and it won't redirect
// Response.Redirect("default.aspx");
}
}