0

I am working on a C# MVC website, and have a popup that redirects its parent with a window.parent.location=newRelativePath statement in JavaScript (and then calls a custom method to hide the popup).

In one place in my application, the redirection works great. The browser adds the correct protocol, host and domain at the start of the relative URL that I pass in, and navigates correctly. In another place in my application, the EXACT SAME CALL (i.e. newRelativePath is the same, being called from a popup, parent window has a URL that follows the same kind of format) doesn't work because the browser not only adds the protocol, host and domain, but also adds the controller name from the path of the prior page at the start of the URL (I get a 404 error saying the url "/domain/oldcontroller/newcontroller/action" cannot be found)

In both cases, my original parent window URL is in the format "protocol://host/domain/controller/action/id?querystring", and newRelativePath is in the format "controller/action?querystring"

I don't see any difference in the format of window.location or window.parent.location at the different spots in the application, but something must be different since the browser treats the relative URL I feed in differently - any ideas what that might be?

Thanks very much for your assistance!

4

1 回答 1

0

而不是使用这样的东西:

newcontroller/action

你必须使用这个:

/newcontroller/action

/开头 的斜线很重要,告诉资源管理器不是相对路径,而是绝对路径。

于 2017-08-22T23:15:30.857 回答