I created an Empty ASP .NET Application and App_Code folder with custom IHttpHandler
:
public class CustomJsonHandler : IHttpHandler
{
/// <summary>
/// You will need to configure this handler in the Web.config file of your
/// web and register it with IIS before being able to use it. For more information
/// see the following link: http://go.microsoft.com/?linkid=8101007
/// </summary>
#region IHttpHandler Members
public bool IsReusable
{
// Return false in case your Managed Handler cannot be reused for another request.
// Usually this would be false in case you have some state information preserved per request.
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
try
{
var employees = JsonConvert.DeserializeObject<List<Employee>>(File.ReadAllText("index.json"));
foreach (var emp in employees)
context.Response.Write(emp + Environment.NewLine);
}
catch (Exception exc)
{
context.Response.Write("Error: " + exc.Message);
}
}
#endregion
}
This custom HttpHandler was registered into web.config:
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.webServer>
<handlers>
<add name="CustomJsonHandler" path="*.json" verb="GET" type="WebApplication4.App_Code.CustomJsonHandler"/>
</handlers>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
I created a new web site in IIS manager and converted my project folder to application. But when I try to open http://localhost:99/WebApplication4/WebApplication4/index.json I get the following error:
Unknown attribute: targetFramework
<system.web>
<compilation debug="false" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
I think that I solved this problem by changing version of .NET Framework in Application Pool config. The version was changed to v4.0. But I got the next error:
Handler "CustomJsonHandler" contains the damaged module "ManagedPipelineHandler" in the list of modules