代ASPX文件

编程入门 行业动态 更新时间:2024-10-21 09:36:46
本文介绍了代ASPX文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们希望能够换出/替代/覆盖ASPX文件偶尔。这是该方案。

We want to be able to swap out/substitute/override ASPX files occasionally. This is the scenario.

我们与ASP.NET有吨的网页已经写了门户网站 - 用于查看数据,更新记录,报告等。有些客户是非常重要的,因此,我们需要能够自定义某些网页只是为了他们,所以当他们登录他们看到的定制他们的页面。

We have a portal written with ASP.NET which has tons of pages already - for viewing data, updating records, reports and so on. Some clients are "really important" and therefore we need to be able to customise certain pages just for them, so when they login they see a page that's customised for them.

母版页是巨大的 - 我们可以自定义页眉,页脚等等,但是我们可能想隐藏某些领域,或完全移动他们周围。我们不能做到这一点与母版页。

Master pages are great - we can customise the header, footer and so on, but we might want to hide certain areas, or move them around completely. We can't do that with Master Pages.

主题/皮肤是良好的CSS,使控制行为不同,但同样,这并不让我完全重组一个特定的页面。

Themes/skins are good for CSS and making controls behave differently, but again this doesn't allow me to completely reorganise a particular page.

所以我想能写code去嘿,我登录的一个特殊的客户端,去找出是否有一个覆盖了一个我在.aspx页面中如果有,则使用。否则,使用的存在已经在.aspx。

So I want to be able to write code to go "Hey, I'm logged in as a special client, go find out if there is an 'override' .aspx page for the one I'm on. If there is, use that. Otherwise use the .aspx that's there already."

这意味着我可以有我与奇.aspx文件服务器为每个我的特殊客户对一个目录有覆盖缺省。

That means I can have a directory on my server for each of my "special clients" with the odd .aspx file in there that overrides the default.

我怎样才能做到这一点?

How can I achieve this?

非常感谢尼克

Many thanks Nick

推荐答案

要做到这一点,你需要注册一个页面工厂处理的.aspx 文件。因此,首先创建一个扩展的新类 PageHandlerFactory :

To do this, you need to register a page factory that handles .aspx files. So first create a new class that extends PageHandlerFactory:

public class MyPageFactory : PageHandlerFactory { public override IHttpHandler GetHandler( HttpContext httpContext, string requestType, string url, string pathTranslated) { // Here you can inspect `HttpContext` and perform whatever checks you // need to determine whether or not to use your custom overridden page. if (shouldOverride) { var newVirtualPath = "/Overrides/Foo/MyPage.aspx"; string newFilePath = httpContext.Server.MapPath(newVirtualPath); // Now create the page instance IHttpHandler page = PageParser.GetCompiledPageInstance(newVirtualPath, newFilePath, httpContext); return page; } else { // If we're not overriding, just return the default implementation return base.GetHandler(httpContext, requestType, url, pathTranslated); } } }

不要忘了在你的 web.config中注册它(IIS7):

<system.webServer> <httpHandlers> <add verb="*" path="*.aspx" type="MyPageFactory" /> </httpHandlers> </system.webServer>

或LT; IIS7:

<system.web> <httpHandlers> <add verb="*" path="*.aspx" type="MyPageFactory" /> </httpHandlers> </sysetm.web>

更多推荐

代ASPX文件

本文发布于:2023-11-10 16:05:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   ASPX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!