【问题标题】:How to configure an Empty ASP .NET Application to publish it to IIS如何配置空 ASP .NET 应用程序以将其发布到 IIS
【发布时间】:2016-11-16 11:36:01
【问题描述】:

我使用自定义 IHttpHandler 创建了一个 Empty 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
}

这个自定义的 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>

我在 IIS 管理器中创建了一个新网站,并将我的项目文件夹转换为应用程序。但是当我尝试打开http://localhost:99/WebApplication4/WebApplication4/index.json 时,出现以下错误:

未知属性:targetFramework

<system.web>
<compilation debug="false" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>

我认为我通过更改应用程序池配置中的 .NET Framework 版本解决了这个问题。版本已更改为 v4.0。但我得到了下一个错误:

处理程序“CustomJsonHandler”在模块列表中包含损坏的模块“ManagedPipelineHandler”

【问题讨论】:

    标签: c# asp.net iis


    【解决方案1】:

    默认更改您的应用程序池 2.0 框架

    Advance Setting -> Change FrameWork 4.5.2 Application Pool
    

    【讨论】:

    • 为什么我应该使用默认应用程序池?我可以用我自己的“abc”池 .NET Framework 4.0 做同样的事情吗?
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多