【发布时间】:2021-05-01 14:20:02
【问题描述】:
我有一个使用MasterPageFile 的内容页面,在代码中我们尝试访问主属性Master.SessionId。
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFrontend.Master" AutoEventWireup="true"
CodeBehind="Reasons.aspx.cs" Inherits="Admin.Other.Reasons" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMainBody" runat="server">
<reason session-id="<%=Master.SessionId%>">
</reason>
</asp:Content>
但Master.SessionId 无法识别,Master 没有引用正确的主文件。类似的代码适用于项目中的另一个文件。我们发现的唯一显着区别是,正常工作的页面在 aspx.designer.cs 文件中有以下自动生成的代码。
public partial class MyChart {
/// <summary>
/// Master property.
/// </summary>
/// <remarks>
/// Auto-generated property.
/// </remarks>
public new Admin.AdminFrontend Master {
get {
return ((Admin.AdminFrontend)(base.Master));
}
}
}
这是我的 Reasons.aspx 文件的设计器。
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Admin.Other
{
public partial class Reasons
{
}
}
I am not sure what is the problem, why in one file that property is auto-generated and not in the other. I thought Visual Studio is doing something crazy. I restarted VS2019 and also tried restarting my machine. Both didn't solve the
问题。
【问题讨论】:
标签: asp.net visual-studio-2019 master-pages