在RewritePath之后,aspx页面呈现为纯文本

时间:2013-04-25 07:36:16

标签: asp.net httphandler httpmodule ihttpmodule

我的ASP.NET应用程序使用HTTP Moule与here相同。但每当我尝试在Application_PostAcquireRequestState中重写路径时,我都将Default.aspx视为纯文本。

有人知道为什么它被渲染成这样而不是被渲染为普通的aspx页面吗?

这是我的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");
    }

}

重写路径后,我看到了:

<%@ 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>

谢谢

0 个答案:

没有答案