HttpHandler的重定向

HttpHandler的重定向

本文介绍了HttpHandler的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个HttpHandler将流量重定向到服务器上的各种网页。
用户将键入 http://www.thisissupposedtoberedirected.com/site12 并应重定向中选取适当的网站,在这个例子网站1.2版

I want to write an HttpHandler to redirect traffic to various webpages on the server.The user will type in http://www.thisissupposedtoberedirected.com/site12 and should be redirected to the appropiate site, in this example site version 1.2

我知道如何在ASP.NET和C#编程,但我似乎没有抢到关于网站管理更精细的细节。

如何管理完成这件事?我应该在web.config吗?我读过这但它没有太大的帮助。

I know how to program in ASP.NET and C# but I don't seem to grab the finer detail about website management.
How can I manage to get this done? What should I do in the web.config? I've read this msdn page but it isn't much help.

推荐答案

HttpHandlers的实际上是相当简单的组件。

HttpHandlers are actually fairly simple components.

首先,你需要创建一个继承或者的IHttpHandler IHttpAsyncHandler (供您使用,我是一个类ð建议的IHttpHandler 因为真的正在做没有繁重)。

First, you need to create a class that inherits either IHttpHandler or IHttpAsyncHandler (for your use, I'd suggest IHttpHandler since there's really no heavy lifting being done).

您然后编译DLL和Web应用程序的bin文件夹中删除它。

You then compile the DLL and drop it in the bin folder of your web application.

现在棘手的部分。在web.config文件中部署HttpHandlers的是棘手的,因为它是IIS6,IIS7集成模式,和IIS7经典模式不同。寻找最好的地方是这个MSDN网页:

Now the tricky part. Deploying HttpHandlers in the web.config file is tricky since it's different between IIS6, IIS7 Integrated Mode, and IIS7 Classic Mode. The best place to look is this MSDN page:

IIS6

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="SampleHandler.new"
        type="SampleHandler, SampleHandlerAssembly" />
    </httpHandlers>
  <system.web>
</configuration>

IIS7的经典模式

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="SampleHandler.new"
        type="SampleHandler, SampleHandlerAssembly" />
    </httpHandlers>
  <system.web>
  <system.webServer>
    <add name=SampleHandler" verb="*" path="SampleHandler.new"
      Modules="IsapiModule"
      scriptProcessor="FrameworkPath\aspnet_isapi.dll"
      resourceType="File" />
  </system.webServer>
</configuration>

IIS7集成模式

<configuration>
  <system.webServer>
    <handlers>
      <add name="SampleHandler" verb="*"
        path="SampleHandler.new"
        type="SampleHandler, SampleHandlerAssembly"
        resourceType="Unspecified" />
    </handlers>
  <system.webServer>
</configuration>

正如你所看到的,每个IIS配​​置需要在web.config文件中略有不同部分的条目。我的建议是在每个位置添加条目,以使IIS配置变化不会破坏你的HttpHandler。

As you can see, each IIS configuration requires entries in slightly different sections of the web.config file. My suggestion would be to add entries in each location so that IIS configuration changes don't break your HttpHandler.

这篇关于HttpHandler的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:01