母版页和虚拟路径提供程序存在问题 [英] Problem with Master Page and Virtual Path Provider

查看:88
本文介绍了母版页和虚拟路径提供程序存在问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dll中构建了一个可部署的母版页,并使用虚拟路径提供程序在多个ASP.NET Web应用程序中对其进行了引用.我遇到的问题是,这确实混淆了我的aspx页面的源视图.

I built a deployable master page into a dll and referenced it in multiple ASP.NET Web Applications using a virtual path provider. The problem I'm having is that this really confuses the source view of my aspx pages.

这是每个aspx.cs页面内的代码,它们实际上将MasterPage附加到每个内容页面,但是正如我所说的那样,现在,我的<asp:Content>标签变得非常混乱,我无法按CTRL K + CTRL + D内容页面,它将对所有内容引发验证错误.帮助!

Here is the code inside each of my aspx.cs pages which actually attatches the MasterPage to each content page, but as I said, now, my <asp:Content> tags get really confused and I cant CTRL K + CTRL + D my content pages anymore, it throws validation errors on EVERYTHING. HELP!

protected override void OnPreInit(EventArgs e)
        {
            MasterPageFile = MasterPageVirtualPathProvider.MasterPageFileLocation;
            base.OnPreInit(e);
        }

推荐答案

要获得对共享MP的设计时支持,您需要为VS提供标记.

To get design time support for shared MP you need to provide markup for VS to work with.

您可以通过以下方式来执行此操作:在您使用的项目中复制MP的标记文件,删除codebehind属性并删除co​​debehind文件,或者在链接后添加空白代码.

You can do this by copying your MP's markup file in you consuming project, removing the codebehind attribute and delete the codebehind file OR add a linked copy with a blank codebehind.

现在将内容页面的主页设置为刚创建的存根,并且应该具有设计时间支持.

Now set your content page's masterpage to the stub you just created and you should have design time support.

您的VPP应该在运行时从嵌入式标记呈现.

Your VPP should render from the embedded markup at runtime.

不是最佳选择,但是如果您需要设计时支持,我认为这是唯一的方法.

Not optimal but if you want design-time support I think this is the only way.

这篇关于母版页和虚拟路径提供程序存在问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆