如何使用Http处理程序和模块 [英] how to use Http handler and module

查看:51
本文介绍了如何使用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处理程序和模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆