2010-09-09 9 views
7
Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context); 

aspxHandler.PreRenderComplete += AspxPage_PreRenderComplete; 
aspxHandler.ProcessRequest(context); 

Quando si chiama Page.Request.Url dopo questo, si ottiene l'URL della pagina che si riscritto perURL Rewriting in asp.net ma mantenendo l'URL originale

... Quello che sto cercando per è di fare una riscrittura, ma per Page.Request.Url di rimanere come l'URL originale che è stato passato in. È possibile?

risposta

10

Ho avuto un problema simile utilizzando le regole di riscrittura in web.config. Non sono sicuro se questo risolverà anche il tuo problema, ma ho scoperto che quando l'url è stato riscritto, l'URL originariamente richiesto era accessibile tramite la variabile del server "HTTP_X_ORIGINAL_URL".

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; 

Questo dovrebbe ottenere il percorso originale e querystring della richiesta prima di riscrittura, anche se non riscrivere ha avuto luogo.

+0

Proprio quello che stavo cercando. Grazie! –

+0

Grazie, holmes. +1 –

+0

Nota che AllKeys è un array e non fornisce un metodo Contains –

Problemi correlati