0

I want my ascx.cs file to work as ashx file for some reason. I have implemented System.Web.IHttpHandler into it and registered it as a handler in web.config

<httpHandlers>
.
.
.
<add path="*.cs" verb="*" type="Namespace.ClassName, Assembly.dll" validate="false" />
</httpHandlers>

And added following code in request filtering under System.WebServer in `web.config'

<security>
  <requestFiltering>
    <fileExtensions allowUnlisted="true">
      <remove fileExtension=".cs" />
      <add fileExtension=".cs" allowed="true" />
    </fileExtensions>
  </requestFiltering>
</security>

but when I open .cs file from browser, it gives me error.

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

with following details

Module StaticFileModule

Notification ExecuteRequestHandler

Handler StaticFile

Error Code 0x80070032

Requested URL http://localhost:80/MyClass.ascx.cs

Physical Path MyPath

Logon Method Anonymous

Logon User Anonymous

Imad
  • 7,126
  • 12
  • 55
  • 112

1 Answers1

0

You have to add a separate section for static files, see here IIS7, web.config to allow only static file handler in directory /uploads of website Its different to exactly what you want, but the static file concept is shown.

Community
  • 1
  • 1
Chris Watts
  • 822
  • 1
  • 9
  • 27
  • sorry, but it has nothing to do with my question. – Imad Feb 08 '16 at 07:21
  • @anonymous You're quite right, i realised after i had posted this was the wrong thing. Should i delete it? Dont want to muddy the water of the responses to your question – Chris Watts Feb 08 '16 at 07:57