开发者

HttpHandler for a specific port

I have a web application built on ASP.NET MVC framework which requires a service payment module. For the given service payment provider, I have to create a module that listens to a specific port (different from 80) at a specific url. What is the best way to achieve this? Should I create a separate Http Server application which would lis开发者_高级运维ten to those connections? Is there a way to create an HttpHandler in the context of the main web application that would process the request for a given port?


I know of two options do this:

  1. As you said create a new web application bound to listen to requests on the specified url & port.
  2. Bind the website to listen to both port 80 and this other URL. Then when you write your handler you could look at the Request object to determine the URL

Personally I prefer the first choice.


In your PostMapRequestHandler event check the port. If it's the port you want to use then set the HttpHandler to be your custom handler, otherwise don't do anything.

For example,

        EventHandler WireThisToHttpApplicationPostMapRequestHandler = (sender, args) =>
              {
                  var httpApplication = (HttpApplication) sender;
                  var portString =httpApplication.Request.ServerVariables["SERVER_PORT"];
                  if (!string.IsNullOrEmpty(portString))
                  {
                      var port = int.Parse(portString);
                      if (port == 8675309)
                      {
                          httpApplication.Context.Handler = new TommyTutoneHttpHandler();
                      }
                  }
              }; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜