我只是不明白为什么RewritePath方法在这段代码中不起作用。 当我尝试从浏览网页ProductPage.aspx项目,在地址栏中的网址仍显示为http://localhost:44789/ProductPage.aspx的而不是这样的: http://localhost:44789/ProductPage.aspx/?color=“URL重写不起作用
这里是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for GetProductInfo
/// </summary>
public class GetProductInfo:IHttpModule
{
public GetProductInfo()
{
//
// TODO: Add constructor logic here
//
}
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
context.BeginRequest += Context_BeginRequest;
}
private void Context_BeginRequest(object sender, EventArgs e)
{
HttpApplication App = sender as HttpApplication;
if (App.Request.Path.Contains("ProductPage.aspx"))
{
string[] Parts = App.Request.Path.Split('/');
App.Response.Write(Parts.Length);
if (Parts.Length < 3)
App.Context.RewritePath("ProductPage.aspx/?Color=");
else
App.Context.RewritePath("ProductPage.aspx?color=" + Parts[Parts.Length - 1]);
}
}
}
更新: 我仍然试图解决这个问题,我试图在不同操作系统的其他机器上运行此代码仍然没有运气
你有没有进入代码并调试它?它是否正确地击中了你的重写代码?它是通过它吗? –
是的,我做到了。其实我在这里看到的东西,我不知道如何处理它: 当我检查app.context我看到了这个:App.Context.IsWebSocketRequest'App.Context.IsWebSocketRequest'抛出了一个异常'System.InvalidOperationException ' 你能帮我解决这个错误吗? –