Url Rewriting in asp.net but maintaining the original url

前端 未结 1 545
自闭症患者
自闭症患者 2021-01-18 02:01
Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context);

aspxHandler.PreRenderComplete += AspxPage_Pr         


        
相关标签:
1条回答
  • 2021-01-18 02:34

    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.

    0 讨论(0)
提交回复
热议问题