locked
Acessing the URL in javascript after rewrite path in HTTPModules RRS feed

  • Question

  • User-1716690740 posted

    Hi , I am rewriteing my path using context.RewritePath in HTTPModules in context_BeginRequest event. Am appending couple of extra query strings..

    Am using the below function in javascript to get the querystring value.But the problem is the rewritten path is not reflected in either "window.location.href" or in "window.location.search" so I am not getting the new querystring that I have added in the HTTPModules.

    function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

    I Would be pleased if some can help me in getting the rewritten path/querystring in Javascript;

    Thursday, October 6, 2011 2:48 PM

Answers

  • User-1716690740 posted

    I was able to fix it with a method in the Masterpage.I can simply call getQueryString() method in the .js file.

     function getQueryString(name)
     {
    var URL = "<%=Request.Url.PathAndQuery%>";
    return getParameterByName(name1, URL);
    }
    function getParameterByName(name,URL) {

    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(URL);
    if (results == null)
    return "";
    else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 11, 2011 3:43 PM

All replies

  • User2001174993 posted

    window.location.pathname

    Saturday, October 8, 2011 1:57 AM
  • User-1716690740 posted

    I was able to fix it with a method in the Masterpage.I can simply call getQueryString() method in the .js file.

     function getQueryString(name)
     {
    var URL = "<%=Request.Url.PathAndQuery%>";
    return getParameterByName(name1, URL);
    }
    function getParameterByName(name,URL) {

    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(URL);
    if (results == null)
    return "";
    else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 11, 2011 3:43 PM