简体   繁体   English

如何在ASPX页面中指定物理路径?

[英]How to specify physical path in ASPX page?

I am developing a C# VS 2008 / SQL Server 2008 ASP.NET Web Applications project. 我正在开发一个C#VS 2008 / SQL Server 2008 ASP.NET Web应用程序项目。 In one of my ASPX files I am trying to reference the Master file, which is actually located in the parent website. 在我的一个ASPX文件中,我试图引用Master文件,该文件实际上位于父网站中。 In other words, when I open the parent website, I see this project listed. 换句话说,当我打开父网站时,我看到了这个项目。 But when I open this project separately, I do not see parent website and this project is the root. 但是当我单独打开该项目时,看不到父网站,并且该项目是根目录。

So now how do I use the Master file from the parent website? 那么,现在如何使用父网站上的Master文件? Currently, I have in my ASPX file: 目前,我的ASPX文件中包含:

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="EnhancedCreateUserWizard.aspx.cs"
    Inherits="Membership_EnhancedCreateUserWizard" Title="Untitled Page" %>

But this won't work because it is a virtual path and since this project is the root, I can't access the Master file virtually. 但是,这是行不通的,因为它是虚拟路径,并且由于该项目是根目录,因此我无法虚拟访问Master文件。 Instead I want to specify physical path. 相反,我想指定物理路径。 How accomplish I do this? 我如何做到这一点?

You cannot share a master page between applications this way. 您不能通过这种方式在应用程序之间共享母版页。 All paths within an asp.net app are relative. asp.net应用程序中的所有路径都是相对的。

The virtual path provider simply will not reach above the current apps root. 虚拟路径提供程序根本无法到达当前应用程序根目录之上。

You will need to either write a custom virtual path provider, which is not trivial, or package the master pages in a shared assembly. 您将需要编写一个简单的自定义虚拟路径提供程序,或者将母版页打包在共享程序集中。

You will find guidance in this question: What is the best way to share MasterPages across projects 您将在以下问题中找到指导: 在项目中共享母版页的最佳方法是什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM