开发者

Proper web redirection with JS window.open call

开发者 https://www.devze.com 2022-12-08 08:31 出处:网络
On a testing server my URL= http: //scantdev04:8086/ActivityReport.aspx I want to prefill a new URL with query data and pass it to the new url:

On a testing server my URL= http: //scantdev04:8086/ActivityReport.aspx

I want to prefill a new URL with query data and pass it to the new url:

string sUrl = sRelativePath + "?Organization=" + sOrganization + "&&StartDate=" + sStartDate + "&&EndDate=" + endDate;

string displayScript = "" + "window.open('" + sUrl + "', 'DisplayReport', " + "'width=1200, height=800, toolbar=yes, menubar=yes, resizable=yes, scrollbars=yes')" + "";

Pretty straight forward.

On dev box, localhost, it is all good.

But in test, the URL spits out like: http://www.displayrep开发者_如何学运维ort.aspx/?Organization=Correctional%20Alternatives,%20Inc&&StartDate=09-01-2009&&EndDate=10/6/2009%2012:00:00%20AM

How do I fix the www. that is now there and repeat the "http://scantdev04:8086/"

I would rather not push this to the web.config but will if necessary.


Where does your sRelativePath string come from?


Found this and it seems to work:

old version: string sRelativePath = Request.ApplicationPath + "/DisplayReport.aspx";

Now changed to :
string sRelativePath = GetWebAppRoot() + "/DisplayReport.aspx";

GetWebRoot() : string host = (HttpContext.Current.Request.Url.IsDefaultPort) ?

       HttpContext.Current.Request.Url.Host : HttpContext.Current.Request.Url.Authority;

   host = String.Format("{0}://{1}", HttpContext.Current.Request.Url.Scheme, host);

  if (HttpContext.Current.Request.ApplicationPath == "/")

         return host;

    else

     return host + HttpContext.Current.Request.ApplicationPath;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号