locked
window.location.href does not work when deployed in Inetpub RRS feed

  • Question

  • User192225791 posted

    I am using Javascript to redirect to the page (and I have to use it for specific reasons) like this:

    window.location.href = '/Home/Read?ResourceID=12'

    When I build and run the project, it is working fine. But when I put the project in Inetpub, I get an error here, because it is constructing a wrong URL.

    I have read this articles : [1] , [2]

    But they weren't a solution to my problem. What is the reason for that and what have I to do?

    Monday, October 12, 2015 3:44 PM

Answers

  • User192225791 posted

    I have found a way to solve this issue:

                   var url = "@Url.Action("Action", "Home")";
                   window.location.href = url;
    

    This is working great in the development area as in Inetpub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 14, 2015 4:00 AM

All replies

  • User281315223 posted

    What does the URL look like when you are attempting to perform this navigation? Is there anything prior to what you are setting your href property to? If not, you may want to consider targeting an absolute URL for your site (since you are pointing it at a relative path). Otherwise, you could use a bit of Javascript to resolve the "base" URL and append your extra section onto it.

    Monday, October 12, 2015 5:20 PM
  • User192225791 posted

    The point is that the URL is working when I run it after building. It crashes if I put it in Inetput. The only difference in the URL in Inetpub with the built URL is:

    The built URL looks like that: http://localhost:57983/

    In Inetpub it is like that: http://localhost:57983/BDE/

    The other URLS where  I am using Html.BeginForm or @Url.Action are working fine, but I have the mess with  window.location.href which I need.

    BTW I don't think absolute URL is the right solution. If I do that I have to worry about any changes in the future and look for every part where I have used an absolute URL

    Tuesday, October 13, 2015 3:17 AM
  • User192225791 posted

    I have found a way to solve this issue:

                   var url = "@Url.Action("Action", "Home")";
                   window.location.href = url;
    

    This is working great in the development area as in Inetpub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 14, 2015 4:00 AM
  • User281315223 posted

    I thought that was the approach you were using before to generate the URL. The Url.Action() method will always generate a fully qualified URL and will encode any characters that require it.

    I wasn't sure if this would be an option for you as you wouldn't be able to do this within an external Javascript file (as it contains actual code-blocks).

    Wednesday, October 14, 2015 9:11 AM