我的 ASP.NET 应用程序使用与此处相同的 HTTP Moule 。但是,每当我尝试在 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>
谢谢