locked
Handler mappings in IIS7 and ASP.NET (VB) RRS feed

  • Question

  • User381004429 posted

    Hi,

    I was hoping someone may be able to help. I have an ASP.NET web site running off IIS7. I am trying to implement a custom handler for different extension types (.pdf, .xls, .docx etc...). I have created a new class that implements IHttpHandler and edited the webServer > handlers section of my web.config file. When I attempt to process a .PDF file, the handler works like a charm - same with bitmaps and other files. My problem occurs when I try to process any MS Office documents - The handler class' ProcessRequest event just isn't being hit and the browser goes ahead and attempts to download the file in question. Anyone have any clues as where I may be going wrong?

    (Edit - Something else to throw into the mix. I created a new test web site and the handler works for all file types! As soon as I did that, .xls files started working in my other website! Now the only files that don't work are newer office files .xlsx, .docx BUT ONLY IN CHROME - Explorer and Firefox trigger the Handler as well. This is such a headache!)

    Here is a snippet from my web.cofig file

      <system.webServer>
        <handlers>
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
          <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
          <add name="WijmoControlsHttpHandler" verb="*" preCondition="integratedMode" path="WijmoControlsResource.axd" type="C1.Web.Wijmo.Controls.WijmoHttpHandler, C1.Web.Wijmo.Controls.4, Version=4.0.20142.176, Culture=neutral, PublicKeyToken=9b75583953471eea" />
          <add name="PDF" path="*.pdf" verb="*" type="fwCommonWeb.FileProtectionHandler" resourceType="Unspecified" />
          <add name="XLS" path="*.xls" verb="*" type="fwCommonWeb.FileProtectionHandler" resourceType="Unspecified" />
          <add name="DOC" path="*.doc" verb="*" type="fwCommonWeb.FileProtectionHandler" resourceType="Unspecified" />
        </handlers>
      </system.webServer>
    

    Hope someone can help,

    Best regards


    Wednesday, May 17, 2017 7:16 AM

All replies

  • User753101303 posted

    Hi,

    And you have also existing PDF and image files? Usually when you try to get a resource, if it matches a physical file then the physical file is returned else code kicks in to process matching requests. You may have a setting to configure that and perhaps skip the physical file (if I remember for example with routing you may to tell if checking the physical file should be skipped). Not sure how to do that with a handler configuration.

    For clarity (and to clearly separate data and app) I never store actual files at the same place.

    Here I would tend perhaps to just use MVC routing.

    Ah what if you add as well preCondition="integratedMode" ?

    Wednesday, May 17, 2017 7:41 AM
  • User381004429 posted

    Hi Patrice,

    Yes all the files are existing on a virtual directory on a separate server. All files are being found and downloaded but not all files are hitting my custom Handler.

    I tried preCondition but this didn't work.

    Thanks

    Wednesday, May 17, 2017 7:50 AM
  • User753101303 posted

    And so you have existing files processed by the handler and other existing files not processed by the handler ? Strange. The remove system is Windows as well (thinking about case sensitive file names ?)

    Do they have to be exposed using a virtual path if anyway your handler is supposed to intercept all calls to them? Until now my personal preference is to just no expose them directly. For example here if the handler is misconfigured they could be accessed directly. My personal preference is that accessing them through my code (handler , actions whateverà is just not possible at all.

    Wednesday, May 17, 2017 7:55 AM
  • User381004429 posted

    Yes, some processed others not!

    I am pretty sure that all the path names are correct - I resolve the virtual directory to a physical path, and I don't think its a character casing issue.

    Its got me stumped because it is only for certain file extensions!

    Wednesday, May 17, 2017 8:04 AM
  • User1771544211 posted

    Hi Soundbomber,

    Its got me stumped because it is only for certain file extensions!

    You can use failed request tracing feature in IIS to trace the detailed process information about including which handler handles the request.

    You can find how to use failed request tracing in the following link.

    https://docs.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

    Best Regards,

    Jean

    Thursday, May 18, 2017 8:30 AM
  • User381004429 posted

    Hi Jean,

    Thanks for the reply. I think I will try this as a last resort - No error codes are being generated and it seems like a lot of work to implement for something that may not help me.

    Thanks again

    Friday, May 19, 2017 7:52 AM
  • User381004429 posted

    Hi Jean,

    Do you have any idea what settings I could use for Failed Request Tracing - I am not getting any error code generated as such.

    Regards,

    Monday, May 22, 2017 2:02 PM
  • User1771544211 posted

    Hi Soundbomber,

    Do you have any idea what settings I could use for Failed Request Tracing - I am not getting any error code generated as such.

    1. Select Your website

    2. Click on the Failed Request Tracing feature

    3. Click Add on the Action panel to add failed request tracing rule

    4. Specify the content you want to trace by configure the extension

    5. Define the trace conditions, in this step you can trace the success request by set the Status Code range to 100-900

    Best Regards,

    Jean

    Tuesday, May 23, 2017 1:25 AM
  • User381004429 posted

    Hi Jean,

    Yes I have already done this but because there is no error code generated it doesnt really help.

    Is there a way of tracing an http request from start to finish without an error being generated?

    Regards,

    Tuesday, May 23, 2017 7:37 AM
  • User1771544211 posted

    Hi Soundbomber,

    Please click the Edit Site Tracing on the Action Panel and make sure you have checked the Enable checkbox.

    Best Regards,

    Jean

    Tuesday, May 23, 2017 7:51 AM
  • User381004429 posted

    Yes,

    Just to clarify, I have done this and tested it with test error codes. My situation is different - no error code is being generated so no log is being created.

    Regards,

    Tuesday, May 23, 2017 8:34 AM
  • User1771544211 posted

    Hi  Soundbomber,

    Please open the log file(xml) using Internet Explorer, if there is no error the log should looks like the image below.

    Then please click on the Request Details tab ->Module Notifications tab to check the module information of your request.

    Best Regards,

    Jean

    Tuesday, May 23, 2017 8:45 AM
  • User381004429 posted

    Jean,

    There is no xml file generated because there was no status code.

    Regards,

    Tuesday, May 23, 2017 9:02 AM
  • User1771544211 posted

    Hi Soundbomber,

    There is no xml file generated because there was no status code.

    When your request is success the status code is 200. So when you set the Failed Request tracing rule to catch the request which status code is 100-999. It will generate the failed request tracing log for the successful request and the status code for the successful request is 200.

    Best Regards,

    Jean

    Tuesday, May 23, 2017 9:06 AM
  • User381004429 posted

    Hi Jean,

    I have generated a success code 200 log file but I don't really know what I am looking for within it. Any pointers?

    Regards

    Friday, May 26, 2017 9:52 AM
  • User1771544211 posted

    Hi Soundbomber,

    Just as I mentioned above, you can check the Request Details -> Module Notifications to find which module executes the request instead of the module you expected.

    Or you can upload your log file to some place that I can download. Then I can check your log and find which module executes your request.

    Best Regards,

    Jean

    Monday, May 29, 2017 1:27 AM
  • User381004429 posted

    Hi Jean,

    I have produced log files for Explorer, Chrome and Firefox. The platform that doesn't work properly is Chrome and interestingly only one file is produced for Chrome but 2 for the other platforms. I'm still not sure what this is telling me though and how to resolve my problem!!

    If you still wouldn't mind taking a look I would be grateful.

    The links are:

    Explorer

    https://wetransfer.com/downloads/ef5423b542d97b538569858922e6949620170530081946/7fc81aaaeaecd86309c6ec2a0913628920170530081946/526a70 

    Chrome

    https://wetransfer.com/downloads/cc031561b1eb31efa7b7a0986d9f552820170530082017/b3a0d0a46b37086e480d73798a1c979420170530082017/43ab11

    Firefox

    https://wetransfer.com/downloads/bf919fdd79e178e043a54f6f7a607e0420170530082041/e9c5562c285c987980371e5b5a674dc220170530082041/7ea281

    Best regards

    Tuesday, May 30, 2017 8:22 AM
  • User1771544211 posted

    Hi Soundbomber,

    Check the Notification column in the failed tracing log-> Find which Notification is "EXECUTE_REQUEST_HANDLER". This is the module which handles your request, you can check if this is the module you expected to execute your request.

    If it isn't the module you expect, you can check the handler Mappings setting to move the order of your custom module to the top of the order list.

    Best Regards,

    Jean

    Wednesday, May 31, 2017 8:15 AM
  • User381004429 posted

    Hi Jean,

    The log file (http://localhost/connect/filestorage/Administration/WHLUK034%20-%20Requisition%20-Travel,%20Accommodation%20Request%20Form%20-%20Rev%201.docx) for the problem browser (Chrome) doesn't exist, just this one (http://localhost/connect/filestore). I have compared this log file for each of the browsers and they appear identical, all using the ManagedPipelineHandler module first, then this - "__DynamicModule_Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.PageInspectorHttpModule, Microsoft.VisualStudio.Web.PageInspector.Runtime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a_176c3f22-bfe5-4799-9f4c-4d080a220b"

    I don't know what this is telling me, but is the fact that the second log file is not being generated in Chrome only not a clue?

    I appreciate your time and help.

    Regards,

    Wednesday, May 31, 2017 8:29 AM
  • User1771544211 posted

    Hi Soundbomber,

    I don't know what this is telling me,

    This tells you which handler executes your request, your log shows that the ManagedPipelineHandler executes your request. Please check the Handler Mapping to see what is the ManagedPipelineHandler. Is it the handler you expected to execute your request?

    but is the fact that the second log file is not being generated in Chrome only not a clue?

    The log shows that the request to the doc file doesn't executed in chrome. Do you request the doc file by typing the url of the doc in browser? Or this behavior is auto executed by some code?

    Best Regards,

    Jean

    Thursday, June 1, 2017 7:19 AM
  • User381004429 posted

    Hi Jean,

    The handler for .docx files is mapped to my custom IHttpHandler class (fwCommonWeb.FileProtectionHandler) in IIS.

    The url is set through code (resolved from a virtual directory).

    Regards,

    Thursday, June 1, 2017 7:56 AM
  • User1771544211 posted

    Hi Soundbomber,

    Soundbomber

    The handler for .docx files is mapped to my custom IHttpHandler class (fwCommonWeb.FileProtectionHandler) in IIS.

    Please check the ordered list of the handler mappings and make sure your custom handler is on top of the ordered list.

    If it isn't on the top of the ordered list, please move it up.

    Soundbomber

    The url is set through code (resolved from a virtual directory).

    Could you please check the code to see if it works on Chrome? 

    Best Regards,

    Jean

    Friday, June 2, 2017 1:41 AM
  • User381004429 posted

    Hi Jean,

    I have moved the handler mapping to the top of the list but without success.

    The url is being correctly resolved in the code.

    Regards,

    Friday, June 2, 2017 7:44 AM