webresource.axd文件的配置及使用
2014-11-17 23:47
190 查看
今天看到同事的代码中使用到了webresource.axd,特地认真地看了一下它的使用。主要用途有两点:
1、当作httphandler用,但是比handler更好用一点,不需要考虑路径,用的时候,只要名称一致就行。
2、用于内嵌js、css等资源文件使用。
首先说第一种使用:
Webconfig文件:
页面代码:
第二种用法从网上学习得知:
链接为:/article/2550961.html
1、当作httphandler用,但是比handler更好用一点,不需要考虑路径,用的时候,只要名称一致就行。
2、用于内嵌js、css等资源文件使用。
首先说第一种使用:
Webconfig文件:
<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <httpHandlers> <!--注册test.axd--> <add verb="*" path="test.axd" type="JHSoft.Example.UILogic.TestAxd,JHSoft.Example.UILogic"/> </httpHandlers> </system.web> <connectionStrings> <add name="BuxiyuanEntities" connectionString="metadata=res://*/BuxiyuanModel.csdl|res://*/BuxiyuanModel.ssdl|res://*/BuxiyuanModel.msl;provider=System.Data.SqlClient;provider connection string="data source=2012-20140730VY;initial catalog=Buxiyuan;user id=sa;password=sa;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration>
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="JHSoft.Example.UILogic.TextBoxSimple" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="http://cdn.renzaijianghu.com/Static/Script/jquery-1.9.1.js"></script> <!--1、直接加载--> <script src="test.axd"></script> <script> <!--2、单击事件加载--> function testAxd() { $.ajax({ type: "post", //要用post方式 url: "test.axd",//test.axd与webconfig中的path的值一样 async: false, success: function (data) { if (data) { alert(data); //结果:弹出HelloWorld! } }, error: function (err) { alert(err); } }); //$.post("test.axd", function (result) { // alert(result); //}); } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" value="testAxd" onclick="testAxd()" /> </div> </form> </body> </html>
注意: 1)、代码中的<!--1、直接加载-->表示,我们可以通过
<script src="test.axd"></script>运行上面的页面时就可以访问到test.axd映射的JHSoft.Example.UILogic.TestAxd.cs类中。 2)、代码中的<!--2、单击事件加载-->表示,我们可以单击按钮触发事件,通过jquery的ajax异步进入JHSoft.Example.UILogic.TestAxd.cs类 下面再给出类文件JHSoft.Example.UILogic.TestAxd.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; namespace JHSoft.Example.UILogic { public class TestAxd : IHttpHandler { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { context.Response.Write("Hello World!"); } } }
第二种用法从网上学习得知:
链接为:/article/2550961.html
相关文章推荐
- 一点点对WebResource.axd的配置及使用[原创]
- 【IIS服务器】 一点点对WEBRESOURCE.AXD的配置及使用
- 备忘:在web.xml中使用org.springframework.js.resource.ResourceServlet的配置对静态资源的访问
- 一点点对WEBRESOURCE.AXD的配置及使用
- .Net Reomting 在WEB客户端里使用配置文件方法
- WINDOWS SERVER 2003从入门到精通之使用IIS服务配置WEB站点 推荐
- 关于使用Spring和hibernate开发web程序的配置说明和简单实例的详细说明
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- 2008年3月小记(设置Windows服务的依赖关系,配置MSMQ的访问权限,WCF的安全配置,删除重建网站,HttpWebRequest,一年中的周,在WCF中使用HttpContext,String.Join)
- 关于WebResource的使用
- 配置适用于正式使用环境下的Tomcat Web服务器双向SSL认证
- Apache Web服务器资源使用限制配置
- 使用 WebResourceCompression 压缩客户端脚本的方法
- 使用IConfigurationSectionHandler在web.config中增加自定义配置
- log4net配置(web中使用log4net,把web.config放在单独的文件中)
- 十分棘手的问题,使用vs2005在文件系统机制下开发出来的web程序,配置到iis就不能正常运行?
- 使用 Visual Studio .NET 开发 Web 项目的远程服务器配置
- Castle ActiveRecord 使用 Web.config 配置数据库连接方式
- ASP.NET中使用web.config配置数据库连接