So I am doing clientside XSL Transformations.
If someone requests Dashboard.aspx it will create all the XML data and by convention include a reference to DashboardXSL.aspx in the XML. This will then be sent over the the client and create the XHTML.
All my aspx pages that serve XML are derived from XMLPage instead of Page, right now I am simply setting the content type there on Page_PreLoad. On the actual Page_Load all the data for the page is being gathered up on ITS Page_Load which is then written to the page via <%=XMLData%>
What I’d like to do is at some point in the process, I am guessing on my XMLPage subclass Page_Render [or PreRender] intercept all the accumulated XML and do a server side transformation and stop the page from being delivered as asp.net would normally deliver it.
Does anyone know how to do this?
Thanks in advance!
Here is my XMLPage class
I am including some code so you have something to visualize
public class XMLPage : System.Web.UI.Page
{
protected void Page_PreLoad(object Sender, EventArgs e)
{
Response.ContentType = "text/xml";
if (Request.Browser.IsBrowser("IE"))
{ //Just testing this out, not production code ! :p
Response.Write(@"<?xml
version=""1.0"" encoding=""ISO-8859-1""?>
<oohru>Browser is IE</oohru>");
Response.End();
Response.Flush();
}
}
}
Here is Dashboard.aspx
<%@ Page Title="Oohru Dashboard" Language="C#" AutoEventWireup="true"
EnableViewState="false"
CodeBehind="Dashboard.aspx.cs" Inherits="OohruWeb.Dashboard"
MasterPageFile="~/MasterPages/LoggedInXML.Master" %>
<asp:Content ContentPlaceHolderID="XMLPageData" runat="server">
<%=DashboardBlogs%>
</asp:Content>
Here is the code behind Dashboard.aspx.cs
public partial class Dashboard : OohruWeb.PageOverloads.XMLPage
{
public string DashboardBlogs="";
protected void Page_Load(object sender, EventArgs e)
{
DbaseExecSpWithRecordset Sproc = new DbaseExecSpWithRecordset();
Sproc.SetSp("sproc_GetBlogPostsForDashboard");
Sproc.AddParam("UserID", System.Data.SqlDbType.UniqueIdentifier,
(Guid)Membership.GetUser().ProviderUserKey);
SqlDataReader Dreader = Sproc.Execute();
while (Dreader.Read())
{
DashboardBlogs += Dreader[0].ToString();
}
Dreader.Close();
Sproc.Close();
Sproc = null;
}
The XSL file is DashboardXSL.aspx, the master page knows to supply this again on name convention. It’s too big to bother posting.
If the only purpose for the page is to render XML, then you might be much better off going with an HTTPHandler.
In fact, you could just replace the existing physical page with a virtual page of the same name. You can generate the XML, transform it, and send it back to the client in response without having to worry about the aspx pipeline.
If you need to work with the session state, you can just implement System.Web.SessionState.IRequiresSessionState in the handler and session state will be made available in the request.