赞
踩
如果用户请求 URL 以 .login 结尾的资源,则 Web 服务器会将该请求转发给 ASP.NET。 然后 ASP.NET 调用 HTTP 处理程序,该处理程序会返回一个响应。 响应由该处理程序动态创建。 无需存在文件扩展名为 .login 的文件。
- using System.Web;
- public class LoginHandler: IHttpHandler
- {
- public loginHandler()
- {
- }
- public void ProcessRequest(HttpContext context)
- {
- HttpRequest Request = context.Request;
- HttpResponse Response = context.Response;
- Response.Write("<html>");
- Response.Write("<body>");
- Response.Write("<h1> HTTP 处理程序</h1>");
- Response.Write("</body>");
- Response.Write("</html>");
- }
- public bool IsReusable
- {
- get { return false; }
- }
- }

Web.config 文件中配置
- <configuration>
- <system.web>
- <httpHandlers>
- <add verb="*" path="*.login"
- type="LoginHandler"/>
- </httpHandlers>
- </system.web>
- </configuration>
测试:
http://localhost/HttpHandler/test.login
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。