A Base page in ASP.NET

后端 未结 5 1088
一向
一向 2021-02-08 06:04

Do you recommend from every web site created in Visual Studio, that you should create a Base page that serves as the parent class?

What are the exact benefits/drawbacks?

5条回答
  •  再見小時候
    2021-02-08 06:47

    It depends on the size and complexity of your project. For small websites with minimal functionality, a base page might be overkill. That said, I would typically use it for site-wide functionality, such as security. I tend to keep functionality in the master pages to a minimum since their primary purpose is to organize your layout and factor out common display areas from you content pages to avoid duplication and ease maintenance.

    To create a base page for use in a master page scenario, you could use the following syntax:

    Master Page:

     <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MyProject.master.cs"
            Inherits="MyProject.MasterPages.MyProject" %>
    
           
        
    

    Base Page:

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/MyProject.Master"
        AutoEventWireup="true" CodeBehind="BasePage.aspx.cs"
            Inherits="MyProject.BasePage" %>
    
    
    
    

    Content Page:

    <%@ Page Title="MyProject - Home" Language="C#"
        MasterPageFile="~/MasterPages/MyProject.Master" AutoEventWireup="true"
            CodeFileBaseClass="MyProject.BasePage" CodeFile="Default.aspx.cs"
                Inherits="MyProject.Default"
                    Meta_Description="Code Snippet: Master Page and Base Page"
                        Meta_Keywords="master, base, content" Theme="Style" %>
    
    
    
    

提交回复
热议问题