如何使用Http处理程序和模块

编程入门 行业动态 更新时间:2024-10-24 11:22:54
本文介绍了如何使用Http处理程序和模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从一台服务器上托管的应用程序重定向到另一台服务器上托管的另一台应用程序。当时我重定向到第二台服务器,如何获取Get Request来自哪台服务器的信息。 我试过以下模块代码。 公共类NewModule:IHttpModule { private const string OriginalUrlKey =CharlieFriendlyUrlModuleRecordOriginalUrl; ////记录原始友好的URL。此值稍后在管道中使用。 private void BeginRequest(对象发送者,EventArgs e) { HttpContext context =((HttpApplication) )发送者).Context; string originalUrl = string.Empty; //从HttpContext.Current.Request获取原始URL的代码 originalUrl = context.Items [OriginalUrlKey] .ToString(); } private HttpApplication _application = null; string path,schme,applicationpath; public void Dispose() { } public void Init(System.Web .HttpApplication context) { //保存上下文 _application = context; //处理结束请求 context.EndRequest + = new EventHandler(context_EndRequest); } //在页面末尾标记一条消息 void context_EndRequest(object sender,EventArgs e) { string message = string.Format(Generated at {0}, System.DateTime.Now.ToString()); / /在响应结束时流式传输 _application.Context.Response.Write(message); } }

I want to Redirect from application one hosted on one server to another application hosted on another server.When I redirect to 2nd server at that time how I get information of Get Request From which sever it comes. I tried following module code. public class NewModule:IHttpModule { private const string OriginalUrlKey = "CharlieFriendlyUrlModuleRecordOriginalUrl"; //// Record the original, friendly URL. This value is used later in the Pipeline. private void BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; string originalUrl = string.Empty; // code to get original URL from HttpContext.Current.Request originalUrl = context.Items[OriginalUrlKey].ToString(); } private HttpApplication _application = null; string path, schme, applicationpath; public void Dispose() { } public void Init(System.Web.HttpApplication context) { // save the context _application = context; // handle the end request context.EndRequest += new EventHandler(context_EndRequest); } // tag a message at the end of the page void context_EndRequest(object sender, EventArgs e) { string message = string.Format("Generated at {0}", System.DateTime.Now.ToString()); // stream it at the end of the response _application.Context.Response.Write(message); } }

推荐答案

这是一个很棒的教程。检查 HTTP处理程序和HTTP模块概述 我希望这会对你有所帮助。 Here is the great tutorial.Check that HTTP Handlers and HTTP Modules Overview I hope this will help to you.

更多推荐

如何使用Http处理程序和模块

本文发布于:2023-11-15 04:05:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   模块   程序   Http

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!