404 Not Found "/default.aspx/ViewDocument"

Hi,

in my VisualStudio, the “GroupDocs.Viewer.WebForm.FrontEnd” run perfectly. But on a IIS, i get the following error: 404 Not Found “/default.aspx/ViewDocument”

Thx

@michaelkohoutek,

Thanks for using GroupDocs.Viewer and posting your issue here. When you publish the application to IIS, you will have to mention your application name (that you have set while publishing the application) in the URLs that are used in the code. Following are the places where you need to add the application name.

  • Use $.ui.groupdocsViewer.prototype.applicationPath = ‘/{YourAppName}/default.aspx’ in default.aspx (see sample)
  • Use “/{YourAppName}/GetResourceForHtml.aspx?documentPath={0}” for each occurance of HtmlOptions.HtmlResourcePrefix in default.aspx.cs (see sample)
  • Prepend application name in the URL for getting resouces for Html in GetHtmlPages function in default.aspx.cs, as shown in the following code sample
               private static List<PageHtml> GetHtmlPages(string filePath, string resourcePath, HtmlOptions htmlOptions, out List<string> cssList)
        {
            var htmlHandler = (ViewerHtmlHandler)HttpContext.Current.Session["htmlHandler"];
            var htmlPages = htmlHandler.GetPages(filePath, htmlOptions);


            cssList = new List<string>();
            foreach (var page in htmlPages)
            {
                var indexOfBodyOpenTag = page.HtmlContent.IndexOf("<body>", StringComparison.InvariantCultureIgnoreCase);
                if (indexOfBodyOpenTag > 0)
                    page.HtmlContent = page.HtmlContent.Substring(indexOfBodyOpenTag + "<body>".Length);

                var indexOfBodyCloseTag = page.HtmlContent.IndexOf("</body>", StringComparison.InvariantCultureIgnoreCase);
                if (indexOfBodyCloseTag > 0)
                    page.HtmlContent = page.HtmlContent.Substring(0, indexOfBodyCloseTag);

                foreach (var resource in page.HtmlResources.Where(_ => _.ResourceType == HtmlResourceType.Style))
                {

                    var cssStream = htmlHandler.GetResource(filePath, resource);
                    var text = new StreamReader(cssStream).ReadToEnd();
                    string appName = "/{YourAppName}"; 

                    var needResave = false;
                    if (text.IndexOf("url(\"", StringComparison.Ordinal) >= 0 &&
                        text.IndexOf("url(\"" + appName + "/GetResourceForHtml.aspx?documentPath=", StringComparison.Ordinal) < 0)
                    {
                        needResave = true;
                        text = text.Replace("url(\"",
                        string.Format("url(\"" + appName + "/GetResourceForHtml.aspx?documentPath={0}&pageNumber={1}&resourceName=",
                        HttpUtility.UrlEncode(filePath), page.PageNumber));
                    }

                    if (text.IndexOf("url('", StringComparison.Ordinal) >= 0 &&
                        text.IndexOf("url('" + appName + "/GetResourceForHtml.aspx?documentPath=", StringComparison.Ordinal) < 0)
                    {
                        needResave = true;
                        text = text.Replace("url('",
                            string.Format(
                                "url('" + appName + "/GetResourceForHtml.aspx?documentPath={0}&pageNumber={1}&resourceName=",
                                HttpUtility.UrlEncode(filePath), page.PageNumber));
                    }

                    cssList.Add(text);

                    if (needResave)
                    {
                        var fullPath = Path.Combine(_tempPath, HttpUtility.UrlDecode(resourcePath), "html", "resources",
                            string.Format("page{0}", page.PageNumber), resource.ResourceName);

                        System.IO.File.WriteAllText(fullPath, text);
                    }
                }

                List<string> cssClasses = Utils.GetCssClasses(page.HtmlContent);
                foreach (var cssClass in cssClasses)
                {
                    var newCssClass = string.Format("page-{0}-{1}", page.PageNumber, cssClass);

                    page.HtmlContent = page.HtmlContent.Replace(cssClass, newCssClass);
                    for (int i = 0; i < cssList.Count; i++)
                        cssList[i] = cssList[i].Replace(cssClass, newCssClass);
                }
            }
            return htmlPages;
        }

Just replace {YourAppName} with your application name. Hope it helps.

We would like to inform you that GroupDocs.Viewer.WebForm.FrontEnd has been marked as obsolete. We recommend you to use the GroupDocs.Viewer for .NET WebForms Modern UI app instead.

Thank you for your help!!!

i am using the viewer in an intranet. My files are blob data on an sql server The web application to show the files, are on the same domain. The viewer and the file web app running in the same applicationpool.
But i get an error when i call the file page(401 Not authorised )!

Utils.cs
In the function DownloadFile(string url, string outputFilePath) i add this line:

request.UseDefaultCredentials = true;

But that does not affect the viewer!!

any ideas???

@michaelkohoutek,

Thanks for coming back. We can see that DownloadFile function in GroupDocs.Viewer.WebForm.FrontEnd is used when you render the files from the URL or stream object. However, from the information you have provided, it is not possible to understand the workflow of your application. Would you please elaborate your scenario in more details, such as:

  • What does file web app do?
  • How are you providing the files to viewer application after retrieving from the database?
  • etc.

You can also share with us the demo applications so that we can test the issue at our end. We shall be looking forward to your response.

  1. the file web app:

wsShowDoc.ashx:

var qDoc = from p in ctxPS.DokumentTMP where p.ID == FileID select p;
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.AppendHeader("Content-Disposition", ("attachment; filename=" + qDoc.First().DokName));
context.Response.BinaryWrite(qDoc.First().Dokument.ToArray());
context.Response.Flush();
context.Response.End();

This ashx is part of the Groupdocs.viewer application!

default.aspx: (http://intranet.zaipublic/psDocViewer/default.aspx)

$(function () {
    var viewerSyle = {
        ScrollView: 1,
        DoublePageFlip: 2,
        OnePageInRow: 3,
        TwoPagesInRow: 4,
        CoverThenTwoPagesInRow: 5
    };

    $('#viewerHtmlDiv').groupdocsViewer({
        //filePath: 'http://groupdocs.com/images/banner/carousel2/signature.png',
        //filePath: $("#hidFileUrl").val(),
        filePath: "http://intranet.zaipublic/psDocViewer/wsShowDoc.ashx?FileID=a348d0b6-31d5-4240-a525-06f4faf0d872&temp=true&ext=.pdf",
        zoomToFitWidth: true,
        //zoomToFitHeight: true,
        showFolderBrowser: false,
        showHeader: true,
        showPaging: true,
        showThumbnails: true,
        showZoom: true,
        //width: 1000,
        height: 900,
        printWithWatermark: true,
        //watermarkPosition: 'Diagonal',
        //watermarkText: '透かし文字、Watermark for Html',
        //watermarkColor: 0x78FF0000,
        //watermarkOpacity: 255,        
 
        isResourcesEmbedded: false,
        useHtmlBasedEngine: true,
        showDownload: true,
        downloadPdfFile: false,
        showPrint: true,
        preloadPagesCount: 1,
        usePdfPrinting: true,
        showDocumentNavigation: true,
        //supportPageRotation: true

    });
    EnableRightClickMenu = false;
    $('#viewerHtmlDiv')[0].oncontextmenu = function () { return EnableRightClickMenu; };
});

after call default.aspx -

{"Message":"Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert.","StackTrace":" bei System.Net.HttpWebRequest.GetResponse()\r\n bei GroupDocs.Viewer.WebForm.FrontEnd.BusinessLayer.Helpers.Utils.DownloadFile(String url, String outputFilePath)\r\n bei GroupDocs.Viewer.WebForm.FrontEnd._default.DownloadToStorage(String url)\r\n bei GroupDocs.Viewer.WebForm.FrontEnd._default.ViewDocument(ViewDocumentParameters request)","ExceptionType":"System.Net.WebException"}

i hope this help, thanks

@michaelkohoutek,

Thanks for providing the details. First of all, please check if your web service is rendering/downloading the PDF document correctly in the browser if you try to directly access the URL: http://intranet.zaipublic/psDocViewer/wsShowDoc.ashx?FileID=a348d0b6-31d5-4240-a525-06f4faf0d872&temp=true&ext=.pdf. Secondly, this issue is not related to the GroupDocs.Viewer API and there may be different reasons behind this exception. In most of the cases, the issue could be related to the credentials. Following articles may be helpful for you in this situation.

Hope it helps.

First, thank you for your patience!!

The solution was to open the path with “loclhost”

http://localhost/psDocViewer/wsShowDoc.ashx?FileID=a348d0b6-31d5-4240-a525-06f4faf0d872&temp=true&ext=.pdf

I think it was a bug of the IIS!

But now:

ExceptionType
:
"System.IO.DirectoryNotFoundException"
Message
:
"Ein Teil des Pfades "D:\wwwroot\psDocViewer\App_Data\temp\http_localhost_psDocViewer_wsShowDoc.ashx_FileID_a348d0b6-31d5-4240-a525-06f4faf0d872_temp_true_**ext_.pdf**\html\resources\page1\styles.css" konnte nicht gefunden werden."
StackTrace
:
"   bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
↵   bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
↵   bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
↵   bei System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
↵   bei System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
↵   bei GroupDocs.Viewer.WebForm.FrontEnd._default.GetHtmlPages(String filePath, String resourcePath, HtmlOptions htmlOptions, List`1& cssList)
↵   bei GroupDocs.Viewer.WebForm.FrontEnd._default.ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, String fileName)
↵   bei GroupDocs.Viewer.WebForm.FrontEnd._default.ViewDocument(ViewDocumentParameters request)"
Name

in then App_Data/temp directory:

http_localhost_psDocViewer_wsShowDoc_ashx_FileID_a348d0b6-31d5-4240-a525-06f4faf0d872_temp_true_**ext__pdf**

Part of the path could not be found. I think only by pdf files.

Why? and many thanks again!

@michaelkohoutek,

Thanks for your response. We are able to reproduce this issue at our end. The issue is not related to the back-end GroupDocs.Viewer API. Instead, it occurs in the front end application. However, we are delighted to inform you that this issue is fixed in our Modern UI App. As the GroupDocs.Viewer.WebForm.FrontEnd is no more supported, we recommend you to migrate to the Modern UI App to get rid of this issue.