ASP.NET - 禁用 WebService 主题
我遇到了与此处描述的相同的问题: http://forums.asp.net/t/1023591 .aspx
我在根 web.config 的
元素中设置了默认页面主题,除了网站的其余部分之外,还应用了该主题到 WebService .ASMX 页面。我想阻止 ASP.NET 将主题应用到 .ASMX 页面。
上述讨论中的答案是,您可以在 .NET Framework 的根 CONFIG 文件夹 (C:\Windows\Microsoft.NET\Framework\VERSION\CONFIG\DefaultWsdlHelpGenerator.aspx) 中编辑“DefaultWsdlHelpGenerator.aspx”并指定 < %@ Page Theme="" %>
,但这仅在您能够访问服务器上的该文件时才有效。
我尝试在 web.config 中添加一个
元素,该元素指向特定的 .ASMX 文件,但这似乎被忽略,因为 .ASMX 页面仍在主题化中。
有没有办法阻止 ASP.NET 将应用程序主题应用到 .ASMX 文件,而无需修改系统级“DefaultWsdlHelpGenerator.aspx”(如上所述)?
编辑
我可以通过允许我的基本页面类型定义应用的主题来解决这个问题,但即使我有解决方法,我想知道是否有一种“正确”的方法来覆盖这种相当荒谬的行为在 ASP.NET 中。
I am experiencing the same issue as described here: http://forums.asp.net/t/1023591.aspx
I have a default page theme set in the <pages />
element of the root web.config, which, in addition to the rest of the website, is being applied to WebService .ASMX pages. I would like to prevent ASP.NET from applying the themes to .ASMX pages.
The answer in the above discussion says you can edit 'DefaultWsdlHelpGenerator.aspx' in the .NET framework's root CONFIG folder (C:\Windows\Microsoft.NET\Framework\VERSION\CONFIG\DefaultWsdlHelpGenerator.aspx) and specify <%@ Page Theme="" %>
, but this only works if you are able to access that file on the server.
I have tried adding a <location />
element to the web.config which points at a specific .ASMX file, but that seems to be ignored as the .ASMX page is still being themed.
Is there any way to prevent ASP.NET from applying application themes to .ASMX files which works without modifying the system-level 'DefaultWsdlHelpGenerator.aspx' (mentioned above)?
Edit
I am able to work around this by allowing my base page type to define the applied theme, but even despite my workaround, I am wondering if there is a 'correct' way to override this rather ridiculous behavior in ASP.NET.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何从 web.config 中删除该行并向您的基页添加一行(希望您有一个)来设置您的默认主题。如果您仍然想通过 web.config 进行管理,您可以为此主题值添加一个 appSettings 条目。
例子:
How about removing the line from the web.config and adding a line to your base page (hopefully you have one), that sets your default theme. If you still want to manage via web.config, you could add a appSettings entry for this theme value.
Example:
如果 .asmx 文件不在网站的根目录中,您不能将另一个 web.config 放入其文件夹中并在那里删除主题吗?
If the .asmx files aren't in the root of the website can't you just put another web.config in their folder and remove the theme there?
请注意,.asmx 文件在任何意义上都不是“页面”。将它们放在受“针对所有页面”执行某些操作的指令约束的文件夹中是不合适的。
要么采纳 Zachary 的建议,要么采纳 詹姆斯·冈特。
或者,更好的是,完全停止使用 ASMX,并转向 WCF。
Note that .asmx files are not "pages" in any sense. Placing them in a folder which is subject to a directive that takes some action "for all pages" is not appropriate.
Either take the suggestion from Zachary, or the one from James Gaunt.
Or, better yet, stop using ASMX at all, and move to WCF.