我创建了一个在其中调用c#方法的Web应用程序。在c#方法中,我返回一个对象,其中包含一个值,如1,2,3.当我在本地主机中运行应用程序时,我得到该对象的确切值。但是,当我在AZURE中发布此应用程序时未做任何更改。我没有得到像1,2,3这样的值,但是我得到了值System.Object。 我不明白这个奇怪的行为。请帮助我。 这里是我的代码:在Azure中发布时Web应用程序的行为有所不同
$('#btn').click(function(){
PageMethods.SaveNDig(obj, OnComplete);
});
C#方法:
[WebMethod]
public static string SaveNDig(Object obj)//string CourseName, string CourseCategoryURL, string CourseCategoryName, string CourseInfo, string PassPercentage, string TextBooks, string GradingSchemes
{
object result = database.ExecuteScalar("select userid from EUser where username ='" + username + "'");
return result;
}
public static object ExecuteScalar(string query)
{
object obj = new object();
try
{
con = InitializeConnection();
cmd = new SqlCommand(query, con);
con.Open();
obj = cmd.ExecuteScalar();
}
catch (Exception ex) { }
finally
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
}
return obj != null ? obj : null;
}
你总是无法放下你的例外情况,看看是否有与您的查询'赶上(例外的一个问题ex){}'添加一些日志或远程调试它。 – RobH
你有没有考虑过使用实体框架?http://msdn.microsoft.com/en-us/data/ee712907.aspx –