[NullReferenceException: 未将对象引用设置到对象的实例。]
Web.Api.WebApiTest.btnCommit_Click(Object sender, EventArgs e) +277
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +114
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +139
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +28
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2980
页面样式
主要功能就是根据下拉列表中的方法去调用指定的webservice
代码如下:
1 string paramJson = txtParams.Text.Trim(); 2 3 Dictionary<string, string> paramDict = null; 4 paramDict = paramJson.FromJsonTo<Dictionary<string, string>>(); 5 6 string apiDomain = string.Empty; 7 if (radDevelop.Checked) 8 { 9 apiDomain = http://localhost:8008/; 10 } 11 else if (radTest.Checked) 12 { 13 apiDomain = http://www.test.com/Api/; 14 } 15 else if (radFormal.Checked) 16 { 17 apiDomain = http://mydomain.com/Api/; 18 } 19 string method = ddlApiListCategory.SelectedItem.Text; 20 string url = string.Empty; 21 switch (method) 22 { 23 case "Area.GetAreaByRegion": 24 url = "CityArea/Area.ashx"; 25 break; 26 case "Area.GetAreaByCode": 27 url = "CityArea/Area.ashx"; 28 break; 29 case "Area.GetCityWithAreaCount": 30 url = "CityArea/Area.ashx"; 31 break; 32 case "Area.GetCityAreaWithAreaCountByCity": 33 url = "CityArea/Area.ashx"; 34 break; 35 case "IndexTopReg.GetTopRegCategoryByCity": 36 url = "Portal/IndexTopReg.ashx"; 37 break; 38 case "IndexTopReg.GetTopRegClassByCityCategory": 39 url = "Portal/IndexTopReg.ashx"; 40 break; 41 case "Class.GetClassByCode": 42 url = "Product/Class.ashx"; 43 break; 44 case "Class.GetClassIntroductionByCode": 45 url = "Product/Class.ashx"; 46 break; 47 case "Class.GetSameNameClassBySearch": 48 url = "Product/Class.ashx"; 49 break; 50 case "Class.GetClassBySearchClassName": 51 url = "Product/Class.ashx"; 52 break; 53 case "Class.GetAreaFilterBySearch": 54 url = "Product/Class.ashx"; 55 break; 56 case "Class.GetPriceFilterBySearch": 57 url = "Product/Class.ashx"; 58 break; 59 } 60 string apiUrl = apiDomain + url; 61 62 //Api接口名称,固定值,区分大小写 64 string appKey = "test"; 65 66 IDictionary<string, string> param = new Dictionary<string, string>(); 67 //Api接口名称。 68 param.Add("method", method); 69 //应用AppKey。 70 param.Add("appKey", appKey); 71 //时间戳,格式为yyyy-mm-dd hh:mm:ss,例如:2008-01-25 20:23:30。API服务端允许客户端请求时间误差为10分钟。 72 param.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); 74 75 if (paramDict != null && paramDict.Count > 0) 76 { 77 param.Add("paramJson", paramJson); 78 } 79 80 string result = HttpUtils.DoPost(apiUrl, param); 82 paramShow.Value = paramJson; 83 resultShow.Value = result;
求各位高手帮忙看看。
打断点 调试,对象为null
忘了说了,本机测试无任何问题,部署到测试服务器出现的这个问题。
下拉框刷新指定了ISPOSTBACK吗?
指定了
两边的.net版本和iis版本一致吗?
一致的
try catch一样,看看具体是那个地方的有问题
可以肯定的是引用变量为null,这个没有检测,就直接使用了
有对象为Null,所以再取对象里面的属性的时候报错了,你仔细检查一下,看看哪些对象为null,比如,数组为null那么在array.Length的时候就会报错等等
已经解决了