在IIS6.0以上版本发布Ajax中,解决添加.v路径找不到的问题?

时间:2022-03-26 06:50:22

问题描述:配置Aiax方式如下:

1.在AppCode中加入文件夹Ajax,加入两个类文件:

  Ajax.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.SessionState;

/// <summary>
///Ajax 的摘要说明
/// </summary>
public interface IAjax : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{
    void ProcessAjax();
    HttpRequest Request { get; }
    HttpSessionState Session { get; }
    HttpResponse Response { get; }
    HttpServerUtility Server { get; }
}

public abstract class Ajax : IAjax
{
    #region IAjax 成员

    public abstract void ProcessAjax();
    private HttpRequest request;
    public HttpRequest Request
    {
        get { return this.request; }
    }

    private HttpResponse response;
    public HttpResponse Response
    {
        get { return this.response; }
    }

    private HttpSessionState session;
    public HttpSessionState Session
    {
        get { return this.session; }
    }

    private HttpServerUtility server;
    public HttpServerUtility Server
    {
        get { return this.server; }
    }


    #endregion

    #region IHttpHandler 成员
    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json; charset=utf-8";
        context.Response.ContentEncoding = Encoding.UTF8;
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        this.request = context.Request;
        this.response = context.Response;
        this.server = context.Server;
        this.session = context.Session;
        ProcessAjax();
    }
    #endregion
}

 AjaxText.cs:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.SessionState;

/// <summary>
/// Summary description for AjaxText
/// </summary>
public abstract class AjaxText : IAjax
{
    #region IAjax 成员

    public abstract void ProcessAjax();
    private HttpRequest request;
    public HttpRequest Request
    {
        get { return this.request; }
    }

    private HttpResponse response;
    public HttpResponse Response
    {
        get { return this.response; }
    }

    private HttpSessionState session;
    public HttpSessionState Session
    {
        get { return this.session; }
    }

    private HttpServerUtility server;
    public HttpServerUtility Server
    {
        get { return this.server; }
    }


    #endregion

    #region IHttpHandler 成员
    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain; charset=utf-8";
        context.Response.ContentEncoding = Encoding.UTF8;
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        this.request = context.Request;
        this.response = context.Response;
        this.server = context.Server;
        this.session = context.Session;
        ProcessAjax();
    }
    #endregion	
}

 加入Web.HttpHandlers.config:

<?xml version="1.0" encoding="utf-8"?>
<httpHandlers>
  <add verb="GET,POST" path="ajaxSupplier.v" type="AjaxSupplier"/>  //type必须和调用的Ajax方法类一样
</httpHandlers>

ajax调用方式:在IIS6.0以上版本发布Ajax中,解决添加.v路径找不到的问题?

 

在IIS6.0的配置,只需要在在IIS6.0以上版本发布Ajax中,解决添加.v路径找不到的问题?中加入应用程序扩展即可,但是在IIS7.0以上的版本后,这样的解决方案一直都是提示找不到.v文件

解决该问题的方案:

 1.可删除掉Web.HttpHandlers.config文件,在Web.config文件中加入节点:system.webServer(两种配置方式),具体内容如下:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <defaultDocument>
      <files>
        <remove value="iisstart.htm" />
        <remove value="index.html" />
        <remove value="index.htm" />
        <remove value="Default.asp" />
        <remove value="Default.htm" />
      </files>
    </defaultDocument>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension=".v" allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
    <handlers>
      <add name="AjaxTest" path="ajaxtest.v" verb="GET,POST" type="AjaxTest"/>
    </handlers>
  </system.webServer>

 或者这样:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="AjaxTest" path="ajaxtest.v" verb="GET,POST" type="AjaxTest"/>
    </handlers>
  </system.webServer>