Which mechanism could be responsible for automatically adding code when rendering ASP.NET pages?
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="fo开发者_开发百科rm1" 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?
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.
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 in CheckoutCompleted
, I would gather that it might be rendered at somepoint in the page hierachy (e.g. what does CheckoutCompleted
inherit from?).
Perhaps in the codebehind?
From aspdotnetfaq:
protected void Page_Init(object sender, EventArgs e)
{
HtmlLink css = new HtmlLink();
css.Href = "css/fancyforms.css";
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}
精彩评论