-1

I have a link that redirects to "/Certification/abc123.asp". Now what I want is page should redirect to some another page that is "details.aspx?URL=/Certification/abc123.asp" but URL in address bar should appear "/Certification/abc123.asp". I have created Url rewriting rule in web.config.

Below is my code: in web.config

 <rule name="Redirects to Certifications" stopProcessing="true">
      <match url="(.*certifications*)"/>
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$"/>
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}/ERRoot/details.aspx?url={REQUEST_URI}"  appendQueryString="true"/>
    </rule>

By this I match my URL, if it contains "certifications" then it redirects to "details.aspx" page with Querystring key "url" that contains original URL. But my URL displays the page i have redirected to.

I want "/Certification/abc123.asp" to display in my address bar.

Note: There is no page like /Certification/abc123.asp. It is just a URL

Please help. Thanks in advance !!!

  • @mjwills My current page is "elist.asp" and i want it to redirect to "details.aspx" but address bar should display "/Certification/abc123.asp". The Link you suggested will not work in this case. – Priyanka Bansal Jun 18 '18 at 05:49
  • `elist.asp` should `Response.Redirect` to `/Certification/abc123.asp`. `/Certification/abc123.asp` should `Server.Transfer` to `details.aspx`. – mjwills Jun 18 '18 at 05:56
  • @mjwills. /Certification/abc123.asp **this page does not exist**. It is just url and there are thousands of urls like this. So we have common template in detail.aspx. Based on querystring "url" we want to display data. I hope you understand my requirement. – Priyanka Bansal Jun 18 '18 at 06:01
  • [This](https://stackoverflow.com/a/10469692/9676724) might help – Ajay Gupta Jun 18 '18 at 06:27
  • @AjayGupta Server.transfer will not work. Because I want to change URL from elist.asp to /Certification/abc123.asp. I think you have missed my **Note. /Certification/abc123.asp page Does Not Exist**. It is only URL I want to display to user and redirect to detail.aspx – Priyanka Bansal Jun 18 '18 at 06:41
  • [This](https://stackoverflow.com/a/10467379/9676724) explains why this isn't possible if you don't want to create a hidden page. – Ajay Gupta Jun 18 '18 at 06:49

1 Answers1

0

This code resolved my problem.

Global.asax:

private void Application_BeginRequest(object sender, EventArgs e)
{
if (System.IO.File.Exists(Request.PhysicalPath))
    {
        // Do nothing here, just serve the file
    }
    // If the file does not exist then
    else if (!System.IO.File.Exists(Request.PhysicalPath))
    {
        if (Request.ServerVariables["URL"].ToString() != "/")
        {
            // Get the URL requested by the user
            string sRequestedURL = Request.Path;

            string varurl = Request.ServerVariables["URL"].ToString().ToLower();
            string sTargetURL = "";

            if (varurl.Contains("/certifications/"))
            {
                sTargetURL = "~/Erroot/details.aspx?url=" + varurl;
            }

            if(sTargetURL!="")
            Context.RewritePath(sTargetURL, false);

        }
    }
}