0

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

Community
  • 1
  • 1
Augis
  • 1,903
  • 1
  • 16
  • 21
  • you mean that you see the html tags and all of that, without the page been render ? – Aristos Apr 25 '13 at 07:39
  • yes. I see markup of the page as above. – Augis Apr 25 '13 at 07:42
  • what is the url which is called by the client ? If it is not aspx, the OriginalHandler might be one that is just designed to deliver plain text – jbl Apr 25 '13 at 10:00
  • original url is: http://localhost/home – Augis Apr 25 '13 at 11:59
  • Does it change anything when setting – jbl Apr 25 '13 at 12:41
  • runAllManagedModulesForAllRequests="true" already was set to "true". By the way, is it possible to use routing in ASP like in ASP MVC? Maybe you know some good examples or tutotials? – Augis Apr 25 '13 at 15:15
  • 1
    Hope this will help http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/url-routing and http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx – jbl Apr 25 '13 at 15:23
  • Thank you so much. It solved my problem. I will use routing :) Thank you SO MUCH!!!! – Augis Apr 25 '13 at 15:58

0 Answers0