My ASP.NET application using HTTP Moule same as here. But whenever I try to rewrite path in my Application_PostAcquireRequestState, I am viewing Default.aspx as plain text.
Does anybody know why it is rendered like this instead of being rendered as normal aspx page?
This is the code of my Application_PostAcquireRequestState
public void Application_PostAcquireRequestState(object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler;
if (resourceHttpHandler != null)
{
// set the original handler back
HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;
}
// -> at this point session state should be available
System.Web.HttpApplication context = (System.Web.HttpApplication)source;
string url = context.Context.Request.RawUrl;
string path = context.Context.Request.Path;
if (path.Contains("home"))
{
//after this it renders Default.aspx as plain text
context.Context.RewritePath("~/Default.aspx");
}
}
After rewriting path I see this:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="M._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="cphContextMain">
<asp:Panel ID="pnBodyContent" runat="server">
</asp:Panel>
</asp:Content>
Thank you