Tuesday, November 7, 2017

How to download a document Web Application accessed from UAG

we can easy to use javascript Window.Open to download a document in IE or popup it up in Chrome and Firefox.

However, the user access the web application from UAG, then error indicates that the document is not found with the url absolute path. since the UAG had block the actual host server of the web application and shown the user with the UAG host server.


it is quick simply to work around it. we should return the relative path to front end for the Window.Open method.

Before:

Window.Open("Http://myserver/myapp/filefolder/myDoc")


After

Window.Open("myapp/filefolder/myDoc")



In the Server, we can use the following snippet code to demonstrate this approach.


   if (baseUrl.Contains("localhost"))
{
    response.fileName = baseUrl + "/Downloads/" + response.fileName ;
}
else
{
    string currentAppFolder = System.AppDomain.CurrentDomain.BaseDirectory;
    if (!string.IsNullOrEmpty(currentAppFolder))
    {
        string parentFolder = string.Empty;
        currentAppFolder = currentAppFolder.Trim('\\');
        int index = currentAppFolder.LastIndexOf("\\");
        if (index > -1) {
            parentFolder = currentAppFolder.Substring(index);
        }
        response.nvisFileName = parentFolder + "/Downloads/" + response.fileName ;
    }
}

No comments:

Post a Comment