开发者

Registering http handler for specific file/folder only OR registering the http handler programmatically

开发者 https://www.devze.com 2023-03-24 03:45 出处:网络
Ok, so I\'m working with an old company website. We\'re talking classic ASP here. I had it working on the development server, but the second it went onto the production server other things on the serv

Ok, so I'm working with an old company website. We're talking classic ASP here. I had it working on the development server, but the second it went onto the production server other things on the server like web services started breaking.

So basically I've added an aspx page that uses a report viewer control. The problem arises when I add the http handler in the web config file. Because the architecture of the site is all screwy I have to modify the root web config file and this is causing problems because the sub directories inherit from the root web config file.

Here is the error I'm getting

Registering http handler for specific file/folder only OR registering the http handler programmatically

Here are the things I've tried which I thought would work.

First I thought adding开发者_开发知识库 a location element to the web config file would work, but no go (of course), it isn't registering the http handler. And it's throwing an error.

<location path="activityreport.aspx">
    <system.web>
        <httpHandlers>
            <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
        </httpHandlers>
    </system.web>
</location>

Next I thought I would move the aspx file into a sub directory and give it its' own web config file registering the http handler there, but that didnt stick either

<system.web>
    <httpHandlers>
        <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
    </httpHandlers>
</system.web>

There is one thing that I did try that does work, but I'm not sure that it wont cause all sub folders to inherit the property.

Setting the location path to "."

<location path=".">
    <system.web>
        <httpHandlers>
            <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
        </httpHandlers>
    </system.web>
</location>

My question is... Is there a way to register this http handler programmatically. Or perhaps you've spotted something wrong with my web config settings.


Your solution that does work will cause the handler to be invoked for all requests to Reserved.ReportViewerWebControl.axd that exist in or below the web root. If you want to isolate your handler to only be accessible from the root, add the entry to the web.config with a / at the start of the path:

<system.web>
    <httpHandlers>
        <add path="/Reserved.ReportViewerWebControl.axd" verb="*" 
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            validate="false"/>
    </httpHandlers>
</system.web>

If you want to isolate everything in a single subdirectory, add the entry to the web.config as follows:

<system.web>
    <httpHandlers>
        <add path="/mysubdir/Reserved.ReportViewerWebControl.axd" 
            verb="*" 
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            validate="false"/>
    </httpHandlers>
</system.web>

Registering the handler with the path specified as:

path="Reserved.ReportViewerWebControl.axd"

will cause the handler to be invoked for any request to Reserved.ReportViewerWebControl.axd, regardless of the subdirectories used.

EDIT
Under IIS6, if you want Reserved.ReportViewerWebControl.axd to only be available from the root, just add a reference to the handler as shown below. You should just have to add a / at the start of the path element.

<system.web>
    <httpHandlers>
        <add verb="*" 
            path="/Reserved.ReportViewerWebControl.axd" 
            type="..." validate="false" />
    </httpHandlers>
</system.web>

If you take this approach and you get a Could not load type 'Microsoft.Reporting.WebForms.HttpHandler' error, then try adding the following to compilation\assemblies in the web.config (you may also have to add that assembly to the GAC):

<system.web>
    <compilation debug="true">
        <assemblies>
            <add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </assemblies>
    </compilation>
    ...
    <httpHandlers>
        ...
    </httpHandlers>
</system.web>


Just a note: I was getting Could not load type 'Microsoft.Reporting.WebForms.HttpHandler' only on our production environment. I added the assembly to the assemblies section under <system.web> and it still didn't work. Then based on this I answer I checked the Global Assembly Cache (GAC) on the machine. Turns out the version for Microsoft.ReportViewer.WebForms on that machine was 9.0.0.0, not 8.0.0.0. I updated that line in web.config and it's working great. Thanks!

0

精彩评论

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