简体   繁体   English

如何配置一个空的ASP .NET应用程序以将其发布到IIS

[英]How to configure an Empty ASP .NET Application to publish it to IIS

I created an Empty ASP .NET Application and App_Code folder with custom IHttpHandler : 我使用自定义IHttpHandler创建了一个空的ASP .NET Application和App_Code文件夹:

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: 此自定义HttpHandler已注册到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=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

</configuration>

I created a new web site in IIS manager and converted my project folder to application. 我在IIS管理器中创建了一个新网站,并将项目文件夹转换为应用程序。 But when I try to open http://localhost:99/WebApplication4/WebApplication4/index.json I get the following error: 但是当我尝试打开http:// localhost:99 / WebApplication4 / WebApplication4 / index.json时 ,出现以下错误:

Unknown attribute: targetFramework 未知属性: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. 我认为我是通过在应用程序池配置中更改.NET Framework版本来解决此问题的。 The version was changed to v4.0. 版本已更改为v4.0。 But I got the next error: 但是我得到了下一个错误:

Handler "CustomJsonHandler" contains the damaged module "ManagedPipelineHandler" in the list of modules 处理程序“ CustomJsonHandler”在模块列表中包含损坏的模块“ ManagedPipelineHandler”

默认情况下更改您的应用程序池2.0 FrameWork

Advance Setting -> Change FrameWork 4.5.2 Application Pool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM