cor*_*ore 4 asp.net httphandler
当我添加HTTP处理程序时:
<add verb="*" path="*test.aspx" type="Handler"/>
Run Code Online (Sandbox Code Playgroud)
上课:
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get { return false; }
}
}
Run Code Online (Sandbox Code Playgroud)
我的ASP.NET应用程序因错误"无法加载类型'处理程序'而死亡." 当我尝试访问http:// localhost:port/mysite/this-is-a-test.aspx时.
我想也许这是一个命名空间问题,所以我尝试了下面的内容,但得到了相同的"无法加载类型'Test.Handler'." 错误.
<add verb="*" path="*test.aspx" type="Test.Handler, Test"/>
Run Code Online (Sandbox Code Playgroud)
上课:
using System;
using System.Web;
namespace Test
{
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get { return false; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我在使用ASP.NET时已经生锈了,但我对这个问题一无所知.
Dar*_*rov 12
我想你正在使用一个网站项目与Web应用程序项目形成对比.在这种情况下,您需要将处理程序(Handler.cs)的代码放在特殊的App_Code文件夹中.标记文件(Handler.ashx)可能位于您网站的根目录:
<%@ WebHandler Language="C#" Class="Handler" CodeBehind="Handler.cs" %>
Run Code Online (Sandbox Code Playgroud)
然后你可以直接在web.config中声明你的处理程序:
<add verb="*" path="*test.aspx" type="Handler"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5836 次 |
| 最近记录: |