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

问题描述:配置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的配置,只需要在中加入应用程序扩展即可,但是在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>

 

  

转载于:https://www.cnblogs.com/xingvskong11/p/3605611.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值