Anonymous February 2016

Use cs file as Web handler

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

Answers


Chris Watts February 2016

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.

Post Status

Asked in February 2016
Viewed 3,365 times
Voted 5
Answered 1 times

Search




Leave an answer