1
A
回答
1
我已经下载了您的解决方案,并得到了它的工作
在App_Start\RouteConfig.cs
你有下面这行需要被删除:
settings.AutoRedirectMode = RedirectMode.Permanent;
而且您的Web方法必须static
1
在App_Start\RouteConfig.cs
更改
settings.AutoRedirectMode = RedirectMode.Permanent;
到
settings.AutoRedirectMode = RedirectMode.Off;
如果Web方法不是在后面的代码静态的,它不会工作。
如果你真的想继续使用代码,你可以通过创建一个静态方法来实现。
实施例:
public class Customer
{
public string CustomerId { get; set; }
public string ContactName { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string PostalCode { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
}
[WebMethod]
public static List<Customer> GetCustomers()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Customers"))
{
cmd.Connection = con;
List<Customer> customers = new List<Customer>();
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new Customer
{
CustomerId = sdr["CustomerId"].ToString(),
ContactName = sdr["ContactName"].ToString(),
City = sdr["City"].ToString(),
Country = sdr["Country"].ToString(),
PostalCode = sdr["PostalCode"].ToString(),
Phone = sdr["Phone"].ToString(),
Fax = sdr["Fax"].ToString(),
});
}
}
con.Close();
return customers;
}
}
}
}
一种更容易的替代方法是创建一个使用实例方法web服务(.ASMX)。
相关问题
- 1. 无法访问的代码背后
- 2. Asp.net代码背后无法访问ascx控件
- 3. 无法访问代码背后的链接按钮的CSS类
- 4. asp.net:在Ajax脚本中调用代码背后的方法
- 5. 我无法从代码访问我的事业部背后
- 6. c代码背后的访问按钮#
- 7. 从类背后的代码访问textarea
- 8. $ .ajax之后无法访问$(document).ready()代码请致电
- 9. 如何从代码背后访问templatefield
- 10. 无法访问代码后面的代码
- 11. 在ASP.NET代码后面访问文档?
- 12. 用户控制访问代码背后的问题
- 13. 笨和Ajax无法访问后
- 14. 访问背后
- 15. ASP.NET无法从后面的代码访问ASP元素(用户控件)
- 16. asp.net ajax代码后面用参数
- 17. 无法从VB代码背后调用javascript代码
- 18. 谈起的iFrame从ASP.NET代码背后
- 19. ASP.NET MVC - 主页背后的代码
- 20. 代码背后的方法与JQuery的AJAX调用
- 21. 无法在代码中访问标签文本文件的背后通过JavaScript
- 22. 无法从asp.net后面的代码中访问标签面板内的gridview
- 23. 在代码中访问的变量用于ASCX背后
- 24. 使用c#等待后,部分代码无法访问
- 25. 获取确定在asp.net代码背后
- 26. 无法访问的代码?
- 27. 无法访问的代码
- 28. 无法访问的代码
- 29. 枚举返回后无法访问的代码
- 30. 无法访问服务后面的代码块
这个错误对我来说似乎很清楚。你如何设置你的认证? – CodeCaster
我试图把本 <位置路径= “SupplyPoints.aspx”> <授权> <允许用户= “*”/> 授权> <认证模式=”无“/> –
comfreakph
这是一个香草的web应用程序,还是通过某种类型的CMS运行? –