哪种机制可以负责在呈现 ASP.NET 页面时自动添加代码?
在 nopCommerce 解决方案中,我们需要将现有的 ASP.NET 页面替换为仅显示一条消息的非常简单的新页面。我们的新 ASP.NET 页面根本没有引用任何与 nopCommerce 相关的内容,没有隐藏代码,没有任何东西可以提示我为什么会发生以下情况:
自动地,一行代码被插入到呈现的 HTML 中(在本例中,是链接到默认主题 css 文件)。
这是新 ASP.NET 文件的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckoutCompleted.aspx.cs" Inherits="CheckoutCompleted" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shop</title>
</head>
<body>
<form id="form1" runat="server">
<div>Your order has now been completed.</div>
</form>
</body>
</html>
这将呈现给浏览器:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Shop</title>
<link href="App_Themes/DarkOrange/styles.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form name="form1" method="post" action="CheckoutCompleted.aspx" id="form1">
<div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQwMDkzNTAzN2Rk4txlLxJclpkuKfo1dNvs77An124dQqbJKyMfrIgvgaY=" /></div>
<div>Your order has now been completed.</div>
</form>
</body>
</html>
CheckoutCompleted.cs(我们自己的新文件)背后的代码如下所示:
public partial class CheckoutCompleted : System.Web.UI.Page
{
}
执行在 Page_Load 中设置的断点处停止,因此正确的.cs 被引用。
所以某种机制添加了一个新行。我检查了 web.config 的提示,但是我想我对一些很酷的 ASP.NET 功能一无所知(独立于 nopCommerce - 我认为他们只是使用它)。
可能是什么?
In a nopCommerce solution, we needed to replace an existing ASP.NET page with a very simple new one that just shows a message. Our new ASP.NET page has no reference at all to anything nopCommerce-related, no code behind, nothing that gives me a hint why the following happens:
Automatically, a line of code gets inserted into the rendered HTML (in this case, a link to a default theme css file).
This is the code of the new ASP.NET file:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckoutCompleted.aspx.cs" Inherits="CheckoutCompleted" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shop</title>
</head>
<body>
<form id="form1" runat="server">
<div>Your order has now been completed.</div>
</form>
</body>
</html>
And this is rendered to the browser:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Shop</title>
<link href="App_Themes/DarkOrange/styles.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form name="form1" method="post" action="CheckoutCompleted.aspx" id="form1">
<div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQwMDkzNTAzN2Rk4txlLxJclpkuKfo1dNvs77An124dQqbJKyMfrIgvgaY=" /></div>
<div>Your order has now been completed.</div>
</form>
</body>
</html>
The code behind CheckoutCompleted.cs (our own, new one) looks like this:
public partial class CheckoutCompleted : System.Web.UI.Page
{
}
The execution stops at a breakpoint set in Page_Load, so the correct .cs is referenced.
So some mechanism adds a new line. I checked web.config for hints, but I guess I'm ignorant of some cool ASP.NET feature (independent of nopCommerce - I think they just used it).
What can it possibly be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
web.config 文件中有一个默认主题设置,应用程序会检查每个页面的主题,如果该页面没有设置主题,它将使用默认主题。默认主题是暗橙色。该行是:
应该在第 59 行左右...
您可以删除此行(只是主题属性,而不是整行),这应该阻止它在没有主题集的页面上使用它,或者...我不确定您正在使用什么主题...或者包装您创建的新页面在母版页中,所以它看起来就像您网站的其他部分。我认为还有一种方法可以在代码隐藏中设置页面主题,但不确定您想要做什么。
There is a default theme setting in the web.config file and the app sort of checks each page for a theme and if that page does not have a theme set it will use the default theme. The default theme is DarkOrange. The line is:
<pages theme="DarkOrange" validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
Should be around line 59...
You can either delete this line (just the theme property, not the whole line) and that should prevent it from using that on pages with no theme set or... I'm not sure what theme you're using... or wrap that new page you created in the master page so it looks like the rest of your site. I think there is also a way to set the theme for the page in the code-behind, but not sure what you're wanting to do.
链接元素可能通过代码隐藏添加到页面标题控件中。您是否检查过
CheckoutCompleted.aspx.cs
以获取有关将该项目添加到标头的位置的任何引用。如果它不在CheckoutCompleted
中,我认为它可能会在页面层次结构中的某个点呈现(例如CheckoutCompleted
继承自什么?)。The link element is likely added to the page header control by codebehind. Have you checked
CheckoutCompleted.aspx.cs
for any reference to where that item is added to the header. If it is not inCheckoutCompleted
, I would gather that it might be rendered at somepoint in the page hierachy (e.g. what doesCheckoutCompleted
inherit from?).也许在代码隐藏中?
来自 aspdotnetfaq:
Perhaps in the codebehind?
From aspdotnetfaq: