现在有一个发布好的WebService,地址是http://hovertree.com:2706/UploadExpenseToConstract.asmx
能不能把最后面的asmx去掉呢?变成
http://hovertree.com:2706/UploadExpenseToConstract
但效果和原来的是一样的?

具体代码:
Global.asax

using System;

namespace ExampleHoverTree
{
public class Global : System.Web.HttpApplication
{ protected void Application_Start(object sender, EventArgs e)
{ } protected void Session_Start(object sender, EventArgs e)
{ } protected void Application_BeginRequest(object sender, EventArgs e)
{
string hPath= Request.Url.LocalPath.ToString().ToLower();
if (!hPath.Contains("/hovertreewm.asmx"))
{
if (hPath.Contains("/hovertreewm"))
{
Context.RewritePath(hPath.Replace("/hovertreewm", "/hovertreewm.asmx"));
}
}
} protected void Application_AuthenticateRequest(object sender, EventArgs e)
{ } protected void Application_Error(object sender, EventArgs e)
{ } protected void Session_End(object sender, EventArgs e)
{ } protected void Application_End(object sender, EventArgs e)
{ }
}
}

HoverTreeWM.asmx

using System.Web.Services;

namespace ExampleHoverTree.HtExample.HWebMethod
{
/// <summary>
/// HoverTreeWM 的摘要说明
/// </summary>
[WebService(Namespace = "http://hovertree.top/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 by 何问起
[System.Web.Script.Services.ScriptService]
public class HoverTreeWM : System.Web.Services.WebService
{ [WebMethod]
public string HLogin(string hUsername,string hPassword)
{
// return hUsername + hPassword;
return (hUsername.ToLower() == "hewenqi" && hPassword == "HoverTree") ? "登录成功" : "用户名或密码错误";
}
}
}

HoverTreeAjax.htm

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asp.net WebService去掉asmx后缀示例_何问起</title>
<script src="http://down.hovertree.com/jquery/jquery-1.12.4.min.js"></script>
<style type="text/css">
.hovertreelogin {
height: 400px;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
</style>
</head>
<body>
<div class="hovertreelogin">
<table>
<tr><td>用户名:</td><td><input type="text" id="husername" /></td><td></td></tr>
<tr><td>密 码:</td><td><input type="password" id="hpassword" /></td><td></td></tr>
<tr><td></td><td><input type="button" value="登录" id="hlogin" /></td><td></td></tr>
<tr><td></td><td><br />正确用户名为:hewenqi<br />密码为HoverTree</td><td></td></tr>
</table>
</div>
<script>
$(function(){
$(function () {
$("#hlogin").on("click", function () {
$.ajax({
type: 'Post',
url: '/HtExample/HWebMethod/hovertreeWM/HLogin',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'hUsername':'" + $("#husername").val() + "','hPassword':'" + $("#hpassword").val() + "'}",
success: function (data, textStatus) {
alert(data.d);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("err " + errorThrown);
}
});
})
})
})
</script>
</body>
</html>

效果图:

源码下载:http://hovertree.com/h/bjaf/hv6cqe5n.htm

推荐:http://www.cnblogs.com/sosoft/p/csharpemail.html

最新文章

  1. Oracle 11g静默安装简明版
  2. Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)
  3. Tsinsen A1493 城市规划(DP + CDQ分治 + NTT)
  4. $(window).height()获取浏览器高度不准
  5. 禁用cookie后session是如何设置的
  6. Ajax案例:三级联动查询员工的信息(三张表进行内连接)
  7. 使用WebClient Post方式模拟上传文件和数据
  8. linux下解决端口被占用的问题
  9. 【转】Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
  10. [LeetCode]Evaluate Reverse Polish Notation(逆波兰式的计算)
  11. MySQL Procedure(MySQL存储过程)[转]
  12. 射频识别技术漫谈(19)——Desfire的3次握手认证和段密码生成
  13. poj2485 highwaysC语言编写
  14. linux 重新生成网卡配置文件
  15. logback使用注意点1
  16. 将文本文件中的\n字符串变成换行符
  17. 也谈创业企业CEO该拿多少工资
  18. aps.net webform框架下页面服务器端控件和html控件用法
  19. GPU下train 模型出现nan
  20. 深入迁出mybatis系列

热门文章

  1. scrpy-cookie
  2. GIT教程的好文章
  3. python实现将android手机通讯录vcf文件转化为csv
  4. Mac系统如何显示隐藏文件?
  5. mount.cifs permission denied
  6. 模拟PLC 的圆弧插补方式在VC中绘制圆弧
  7. zabbix 本地编译安装
  8. 剑指offer——二叉树的镜像
  9. loadrunner飞机订票系统从登陆订票退票登出的脚本实现代码调试通过
  10. 如何用MATLAB读stl并显示点云文件