Asp.net:如何在子文件夹中制作单独的皮肤版本? [英] Asp.net: how to make a separately skinned version in a subfolder?
问题描述
我正在为客户制作我们的ASP.NET网站的OEM皮肤版本。我需要在当前架构中创建一个子文件夹,看起来像我们的主站点,除了用不同的图像重新设置页面。
网站使用一个主站点如果我可以将所有请求重定向到子文件夹到主层次结构中的相应页面,那么我认为我可以处理那里的所有蒙皮。然后主页代码隐藏可以检查原始URL并相应地调整图像。
喜欢这样:
http://my.website.com/OEM/page.aspx
就像
http://my.website.com/page.aspx
但图片不同。
我尝试了什么:
我在子文件夹中创建了一个Default.aspx,在代码隐藏中我调用了Server 。传递()。这似乎适用于主页面,但当我尝试访问任何其他页面时,我得到错误404.
现在我太懒了,无法为其创建文件网站上的每个页面,所以我想知道是否有办法配置文件夹将每个请求汇集到/ OEM / *到/OEM/Default.aspx,甚至将所有请求自动转移到另一个文件夹。
请注意,我不想使用HTTP重定向;传输应该只在服务器端进行。
听起来你需要 URL重写 [ ^ ]模块。
< system。 webServer >
< 重写 >
< 规则 >
< rule name = 网站皮肤 >
< match url = ^(OEM)/([^?] *)(。*)
/ >
< ; action type < span class =code-keyword> = 重写 url = {R:2}?_ skin = {R:1} appendQueryString = true / >
< / rule >
< / rules >
< / rewrite >
< / system .webServer >
这将重定向oem / anyPage。 aspx?查询
到anyPage.aspx?_skin = oem& query
;然后,您可以使用_skin
查询字符串变量来决定使用哪个皮肤。
将其扩展到其他文件夹就像在< match>
元素中添加其他值一样简单:
< 匹配 url = ^(OEM | OEM2 | Another)/([^?] *)(。* )
/ > 跨度>
I am making an OEM skinned version of our ASP.NET site for a customer. I need to make a subfolder in the current architecture look like our main site, except that the pages are re-skinned with different images.
The web site uses one master page to do the layout, so I figure that I can handle all the skinning there, if I could redirect all requests to the subfolder to its corresponding page in the main hierarchy. Then the master page code-behind can check the original URL and adjust images accordingly.
Like so:
http://my.website.com/OEM/page.aspx
would be exactly like
http://my.website.com/page.aspx
but with different images.
What I have tried:
I created a Default.aspx in the subfolder, and in the code-behind I call Server.Transfer(). This seems to work for the main page, but I get Error 404 when I try to access any other pages.
Now I am far too lazy to make a file for every page on the web site, so I wonder if there is a way to configure the folder to funnel every request to /OEM/* to /OEM/Default.aspx, or even to have all requests automatically transferred to a different folder.
Note that I would not like to use HTTP redirects; the transfer should happen in the server side only.
Sounds like you need the URL Rewrite[^] module.
<system.webServer> <rewrite> <rules> <rule name="Site Skin"> <match url="^(OEM)/([^?]*)(.*)
" /> <action type="Rewrite" url="{R:2}?_skin={R:1}" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer>
This will redirectoem/anyPage.aspx?query
toanyPage.aspx?_skin=oem&query
; you can then use the_skin
query-string variable to decide which skin to use.
Extending it to other folders is as simple as adding another value to the<match>
element:
<match url="^(OEM|OEM2|Another)/([^?]*)(.*)
" />
这篇关于Asp.net:如何在子文件夹中制作单独的皮肤版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!