如何指定相对于当前的母版页文件的路径 [英] How to specify path relative to current Master Page File

查看:141
本文介绍了如何指定相对于当前的母版页文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来asp.net,但是母版页似乎做什么,我需要 - 让我来配置不同的模板/ presentations /风格在运行,所以我的应用程序可能会采取不同的外观和选择的感觉不同的母版页。每个母版页坐在自己的文件夹了一组为模板量身定做图片 - 那么我想,在内容页,引用各种图像坐在当前选定的母版页的文件夹中,例如导航按钮在DataPager的:

I am new to asp.net but Master Pages seem to do what I need - allow me to configure different templates/presentations/styles in runtime, so my app may take on a different look and feel by selecting a different Master Page. Each Master Page sits in its own folder with a set of images tailored for that "template" - I then want, in content pages, to reference various images sitting in the folder of the currently selected Master Page, for example the navigation buttons in a DataPager:

<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" 
    PageSize="25">
<Fields>
    <asp:NextPreviousPagerField ButtonType="Image" ShowFirstPageButton="True" 
        ShowNextPageButton="False" 
        FirstPageImageUrl="<<Current Master Root>>/img/action-first.png" 
        PreviousPageImageUrl="<<Current Master Root>>/img/action-prev.png" />
    <asp:NumericPagerField ButtonCount="10" NextPageText="&gt;&gt;" 
        PreviousPageText="&lt;&lt;" />
    <asp:NextPreviousPagerField ButtonType="Image" ShowLastPageButton="True" 
        ShowPreviousPageButton="False" 
        LastPageImageUrl="<<Current Master Root>>/img/action-last.png"
        NextPageImageUrl="<<Current Master Root>>/img/action-next.png" />
</Fields>
</asp:DataPager>
TEST: "<%= System.IO.Path.GetDirectoryName(MasterPageFile) %>" 
(this does not work if we try to use it inside the DataPager?)

有没有做这种取之有道,像蒂尔达〜字符用于获取到应用程序的根文件夹?在code设置这也被证明是单调乏味的,尤其是像DataPager的东西,其中属性嵌套子控件的动态列表(例如,我不知道如何设置属性DataPager1.Fields [0]。接下来在code previousPagerField.FirstPageImageUrl)。

Is there a proper way to be doing this, like the tilda ~ character is used to get to the application root folder? Setting this in code is also proving to be tedious, especially for things like DataPager where the properties are nested in dynamic lists of sub controls (For example I do not know how to set the property DataPager1.Fields[0].NextPreviousPagerField.FirstPageImageUrl in code).

我发现想这样做有主题,需要更多的代码比我开始用,因为我必须包括在皮肤文件中的整个控制的定义,不只是图像的URL属性,然后我不得不重复那个$ C $ ç在每一个主题/皮肤。如果我碰巧想按钮和/或数字字段的不同配置的DataPager的话,我要重复这些变化在每一个皮肤文件还。如果让我在日后发生变化,我将不得不记住要在所有的皮肤也是变化 - 认真击败从皮肤分离code的目的

I have found trying to do this with Themes requires more coding than I started with because I have to include the entire control definition in the skin file, not just the image url properties, and then I have to duplicate that code in every single theme/skin. If I happen to want a DataPager with a different configuration of buttons and/or numeric fields then I have to duplicate those variations in every skin file also. If I make a change at a later date I will have to remember to make that change in all skins also - seriously defeating the purpose of separating the code from the skin.

我的应用程序运行多个项目,每个项目可以选择自己的模板。对于整个应用程序,我想说:如果当前项目使用TemplateX然后从文件夹/ TemplateX / IMG /使用图像,如果TemplateY是seletected然后使用从/ TemplateY / IMG /图像。正如你所知道的CSS不能总是在决定使用什么样的形象,其中的依据,所以我们必须要能够直接放在HTML输出的图像引用。

My application runs multiple projects, and each project may select its own template. For the entire application I want to say: if the current project uses TemplateX then use images from folder /TemplateX/img/, if TemplateY is seletected then use images from /TemplateY/img/. As you know CSS cannot always be relied upon to determine what image to use where, so we have to be able to put the image reference directly in the HTML output.

在自定义ISAPI DLL的网络系统我发展,我只是使用像[#HTML.Template] /img/$p$pv.png一个替换字符串粘模板文件夹中的图片URL的前面。有没有可能是一种方法,我可以挂钩一个定制的.aspx preprocessor手动替换所有ocurrences,如上面的例子,&LT;&LT;当前主服务器根>>?与当前选定的文件夹

In the custom ISAPI DLL web system I developed I simply use a substitution string like "[#HTML.Template]/img/prev.png" to stick the template folder in front of the image URL. Is there perhaps a way I can hook a custom .aspx preprocessor to manually substitute all ocurrences of, as in the example above, "<< Current Master Root >>" with the currently selected folder?

推荐答案

尝试使用smething这样

try use smething like this

var path = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;

这篇关于如何指定相对于当前的母版页文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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