Any alternative to replace original URL?RSS

4 replies

Last post May 10, 2020 10:44 PM by hrk

  • Any alternative to replace original URL?

    Dec 20, 2019 05:44 PM|hrk|LINK

    Hello:

    I need to let users to enter urls such as
    Http://domain name/a number. So that I could change the URL to http://domain name?id=the number.
    I know that this is possible through the rewrite rule and there are examples of it on the web. However, I was thinking if there is any possibility to first let iis to redirect to a custom error page as the original URL is not recognized. And then within the error page get the original URL and make all necessary changes and redirect again to the modified URL.

    It seems to me that is not possible to get the original URL in the custom error page and that should be the reason that Microsoft created the rewrite module. I also thought that the rewrite rule is for many other complicated reasons too.
    So as I am new to the subject, I thought it might be worthwhile to ask if there is any possibility to get the original URL after redirection to the custom error page without using the rewrite rule.

    If it is not possible to accomplish such task without the rewrite rule, could you please tell me with example code how could I send the original URL to a custom error page using the rewrite rule? The original URL in the custom error page would be beneficial because instead of simply creating name, value query string parameter and replacing the original URL with the rewrite rule, I could do other things easier in ASP within the custom error page.

    Thank you for your response.
  • Re: Any alternative to replace original URL?

    Dec 23, 2019 06:36 AM|Yuk Ding|LINK

    Hi hrk,

    I'm just wondering why don't you just make change in the original URL Http://domain name/a number? Since redirection is pure client side operation, we will never be able to inject original URL  to the redirection request via URL rewrite.

    The only workaround to let this happen is when user access  Http://domain name/a number. The server need to send a cookie to the client side with the original URL. Then you need to manual redirection to your custom error page. Because its not possible to create error page for 200 response. Finally, you could let custom error page to make change and redirect to http://domain name?id=the number.

    If the reply is helpful, it is appreciated if you could mark it as answer.

    Best Regards,

    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Any alternative to replace original URL?

    Dec 23, 2019 04:10 PM|hrk|LINK

    Hi Jokies Ding:

    Thank you for your response I appreciate it.
    In response to why don’t I just replace the original URL by using the rewrite rule, I thought it might be better if I do not add one more module (the rewrite module) to avoid crowding the iis with new modules. I only used common sense and I hope that my reason makes sense to you.
    Also, presently I have set a custom error page (errorPage.asp) as response to error code 404. So that if user types the URL www.domainName.com/aNumber the server does not realize the URL and redirects to errorPage.asp.
    So I thought that on the errorPage.asp I could modify the original URL (if I could have the original URL) and then redirect to the modified URL. I thought this method would be beneficial because later if there is any need to add other functions on the errorPage.asp everything could be done easier by ASP.

    I am not sure if I understand your second paragraph where you wrote: ‘The only workaround to let this happen is when user access  Http://domain name/a number. The server need to send a cookie to the client side with the original URL.’
    This is exactly what I need to know. How the server could send a cookie to the client side with the original url?

    Could you clarify that for me?

    Thank you
  • Re: Any alternative to replace original URL?

    Dec 25, 2019 07:51 AM|Yuk Ding|LINK

    Hi hrk,

    You need a specific page or route in your application  for  Http://domain name/a number instead of let IIS 404 to handle a non-exist page and do redirect. IIS itself  are not able to inject cookie.

    Please Use httpcookie class to create cookie.

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httpcookie?view=netframework-4.8

    Then read it from httpcontext.request.cookies dictionary.

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httpcontext.request?view=netframework-4.8

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httprequest.cookies?view=netframework-4.8

    Since there are tons of sample about how to send/read cookie, you may check that and then you will know how to apply that.

    If the reply is helpful, it is appreciated if you could mark it as answer.

    Best Regards,

    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Any alternative to replace original URL?

    May 10, 2020 10:44 PM|hrk|LINK

    Hi Yuk Ding:

    Thank you for responding to my question.
    I managed to work with the rewrite module finally but I had to be away from my work for long. Now because of the changes that I made to my windows 10 system with the rewrite module, I have a new problem and I hope it is appropriate that I continue in this blog.

    After installation and configuration of the rewrite module, I realized that the MSWC.adRotator component does not work anymore on my computer although for a while it was working intermittently. I don't know if it makes sense to think that installation of the rewrite module affected the MSWC on my system but I do not understand why now the adRotator does not work.

    Initially, the adRot.dll was missing on my windows 10 system So I copied the old adrot.dll from my XP system and I installed it on my new windows 10 computer.
    I don’t remember what method I initially used to install the adrot.dll which I had copied from my XP system. Now that the dll was not working anymore, I uninstalled the adrot.dll and I reinstalled it using the commands:
    c:\windows\sysWin64 > Regsvr32 /u c:\windows\sysWin64.dll
    c:\windows\sysWin64 > Regsvr32 c:\windows\sysWin64.dll

    Now I did the same in c:\windows\system32 folder.

    But the problem persists and the adRotator object is not created on my classic ASP page when executing the following line:
    Dim myAds: set myAds = Server.CreatObjecy(“MSWC.adRotator”)

    So that typename(myAd) return the string “Empty” and ads are not displayed. Also the error objectes throws “Object required” when the following line is executed:
    Response.write myAd.getAdvertisement(valid path to file.txt)

    Would you or any other expert be able to tell me why the adRotator object is not created anymore and how could I resolve this issue?
    I am using iis10 on 64bits system to run 32bit classic ASP.

    Your help is greatly appreciated.

    Thank you