问题描述
Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context);
aspxHandler.PreRenderComplete += AspxPage_PreRenderComplete;
aspxHandler.ProcessRequest(context);
在此之后打电话Page.Request.Url,你得到你重写页面的网址
When you call Page.Request.Url after this, you get the Url of the page you rewrote to
...我要找的是做一个重写,但Page.Request.Url继续作为中传递原始URL。这可能吗?
...what I'm looking for is to do a rewrite, but for Page.Request.Url to remain as the original url that was passed in. Is that possible?
推荐答案
我不得不使用重写规则在web.config类似的问题。不知道这是否会解决您的问题,但我却发现,当URL被改写,最初请求的URL是通过HTTP_X_ORIGINAL_URL服务器变量访问。
I had a similar problem using rewriting rules in the web.config. Not sure if this will solve your problem too, but I found that when the url was rewritten, the originally requested URL was accessible through the "HTTP_X_ORIGINAL_URL" server variable.
VB:
string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables("HTTP_X_ORIGINAL_URL") : Request.Url.PathAndQuery
C#:
string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables["HTTP_X_ORIGINAL_URL"] : Request.Url.PathAndQuery;
这应该让你请求的原始路径和查询字符串重写,无论是否重写已经发生了。
That should get you the original path and querystring of the request before rewriting, whether or not rewriting has taken place.
这篇关于URL重写在asp.net但保持原始地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!