标签: webmethod

aspx.cs页面中的ASP.NET Webmethod无法访问Page.Request对象

有没有人知道如何使用aspx.cs页面中的[WebMethod]属性访问静态方法中的HttpRequest.Cookies?

它不会让我这样做,因为方法是静态的.

[WebMethod]
public static bool PostToTwitter(string identityUrl, string message, bool autoFollow)
{
  Page.Request.Cookies -- object reference is required for non-static field
Run Code Online (Sandbox Code Playgroud)

谢谢!

asp.net httprequest webmethod

3
推荐指数
1
解决办法
5733
查看次数

JQuery AJAX发布到asp.net webmethod永远不会被调用

我在我的一个aspx页面中有一个web方法:

[WebMethod]
public static string AddDebt(int userId, int type, string description, float amount)
Run Code Online (Sandbox Code Playgroud)

在aspx页面中我有JQuery

$(".addDebt").click(function (e) {
            e.preventDefault();
            var userId = $("[id$='txtUserId']").val();
            var type = $("[id$='ddlExistingDebtType']").val();
            var description = $("[id$='txtExistingDebtLender']").val();
            var amount = $("[id$='txtExistingDebtAmount']").val();

            var results = new Array();
            results.push({ userId: userId });
            results.push({ type: type });
            results.push({ description: description });
            results.push({ amount: amount });
            var dataString = JSON.stringify(results);
            $.ajax(
            {
                type: "POST",
                url: "register_borrower_step4.aspx/AddDebt",
                data: dataString,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    $(".pDebtsTable").text(result);
                }
            });

        }); …
Run Code Online (Sandbox Code Playgroud)

jquery ajax.net webmethod

3
推荐指数
1
解决办法
6864
查看次数

使用WebMethod读取cookie但没有Request.Cookies集合

我试图在没有回复的情况下阅读cookie.我使用WebMethod来保存cookie,但无法找到检索它的方法.出于某种原因,我找不到Request.Cookies集合,以便我可以检索它的值.任何帮助将不胜感激!

asp.net cookies webmethod

3
推荐指数
1
解决办法
4320
查看次数

从angularJS中的Asp.Net Webmethod和Consume获取Json数据

任何人都可以指导我如何从asp.net webmethod获取json数据,并在angularJS中使用它.

app.controller('MainController', ['$scope', function ($scope, $http) { 
    try { 
    $http({ method: 'GET', url: 'ProblemList.aspx/GetProblemList' })
.success(function (data, status, headers, config) { 
    alert(data); }).error(function (data, status, headers, config) { 
    }); 
    } catch (e) { 
    throw e; 
    } 
Run Code Online (Sandbox Code Playgroud)

asp.net webmethod angularjs

3
推荐指数
1
解决办法
1万
查看次数

jsTree - 使用AJAX/C#Web方法动态填充树

我有一个div,我想用jsTree填充:

我得到了要显示树的"正在加载"图标,但是,即使没有抛出,也会出现javascript错误.

我从AJAX请求加载我的文件夹结构,如下所示.Documents.aspx/GetFolders Web方法返回包含FolderId,ParentId和Folder Name的List.我调试了Web方法,它将正确的结果传递给jsTree"数据"函数.

$.ajax({
   type: "POST",
   url: 'Documents.aspx/GetFolders',
   contentType: "application/json; charset=utf-8",
   success: function (data) {
      data = data.d;

      $("#tree").jstree({
         "core": {
            "themes": {
               "responsive": true
            },
            "data": function () {
               var items = [];
               items.push({ 'id': "jstree_0", 'parent': "#", 'text': "Documents" });
               $(data).each(function () {
                  items.push({ 'id': "jstree_" + this.DocumentFolderId, 'parent': "jstree_" + this.ParentId, 'text': "" + this.Name });
               });
               return items;
            }
         },
         "types": {
            "default": {
               "icon": "fa fa-folder icon-lg"
            },
         },
         "plugins": ["contextmenu", "dnd", "state", …
Run Code Online (Sandbox Code Playgroud)

javascript ajax webmethod jstree c#-4.0

3
推荐指数
1
解决办法
5281
查看次数

使用ServiceStack.Client超时

我一直在使用服务堆栈通过AJAX调用一段时间没有问题,但最近创建了一个快速winforms应用程序,它利用服务堆栈客户端(特别是JsonServiceClient).

但是 - 我遇到了一个问题,即我在第一次TWO尝试成功运行的呼叫中始终获得超时.它看起来像服务堆栈客户端持有某些资源,或者我以错误的方式使用客户端.它仅在针对远程服务运行时发生(每次在本地计算机上运行).这是我的代码,例外:

        var url = "http://www.TestServer.com/api";
        var taskId = Guid.Parse("30fed418-214b-e411-80c1-22000a5b9fe5");
        var email = "admin@example.com";

        using (var client = new JsonServiceClient(url))
        {
            var result = client.Send(new Authenticate {UserName = "username", Password = "Password01", RememberMe = true});
            client.Put(new AssignTask { AdminTaskId = taskId, Assignee = email });//Call #1 - works fine
            client.Put(new AssignTask { AdminTaskId = taskId, Assignee = email });//Call #2 - works fine

            try
            {
                client.Put(new AssignTask { AdminTaskId = taskId, Assignee = email });//Call #3 - works …
Run Code Online (Sandbox Code Playgroud)

httpwebrequest webmethod servicestack

3
推荐指数
1
解决办法
2132
查看次数

从静态方法访问QueryString/Session?

我使用ASP.Net和静态WebMethod/PageMethod来做一些异步工作.我的问题是如何在这里访问我的queryStrings和Session变量?

我尝试了"HttpContext.Current",这里有很多信息,但不是我的QueryString,也不是我的Session,我不知道为什么.

 [WebMethod(EnableSession=true)]
    public static object Update(string time)
    {
        string timer;
        string lastBidder;
        string price;

        //Countdown timer
        DateTime dt = DateTime.Parse(time);
        dt = dt.AddSeconds(-1.0);
        timer = dt.ToString("HH:mm:ss");

        int auctionID = 6;
        if (!int.TryParse(HttpContext.Current.Request.QueryString["id"], out auctionID))
            throw new Exception("Seitenaufruf ohne ID");

        Business.AuctionHandling ah = new Business.AuctionHandling();
        DAL.Auktion auktion = ah.GetSingleAuction(auctionID);

        price = auktion.AktuellerPreis.ToString("###0.00");

        //this.gvHistory.DataBind();

        List<DAL.Biethistorie> his = ah.GetBidHistoryForAuction(auctionID);
        if (his.Count > 0)
        {
            lastBidder = his[0].Benutzer.Benutzername;
            //History fett
            //gvHistory.Rows[0].Font.Bold = true;
            //gvHistory.Rows[0].ForeColor = System.Drawing.ColorTranslator.FromHtml("#3B4D5F");
            //lblHöchstesGebot.ForeColor = System.Drawing.Color.Black;
        }
        else
        {
            lastBidder …
Run Code Online (Sandbox Code Playgroud)

asp.net webmethod

2
推荐指数
2
解决办法
1万
查看次数

来自ASP.NET的多个返回值的JQuery Ajax

如何在成功函数中从JQuery.Ajax()返回多个值?

我尝试过这个:

          $.ajax({
                type: "POST",
                url: "default.aspx/myFunction",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("#myDiv").html(msg.a[0]);
                    $("#myDiv2").html(msg.a[1]);
                }
            });
Run Code Online (Sandbox Code Playgroud)

在这里我的ASP.NET页面:

<WebMethod()> _
Public Shared Function myFunction() As Array

     Dim a() As String
     a(0) = "value 1"
     a(1) = "value 2"

     Return a

End Function
Run Code Online (Sandbox Code Playgroud)

它只在唯一的返回字符串中工作,但数组不起作用:(

asp.net ajax jquery webmethod

2
推荐指数
1
解决办法
6954
查看次数

分析器错误消息:无法创建类型'WebService.asmx.cs'

我正在按照教程从用户输入的SQL服务器创建动态搜索结果.它告诉我创建一个.asmx文件,这不是我之前曾经使用过的格式.我现在有一个.asmx和.asmx.cs文件.这是我到目前为止的代码:

WebService.asmx.cs:

public class SearchService : WebService
{
  [WebMethod]
  public searchResult[] Search(string txtSearch)
  {
//Declare collection of searchResult
        List resultList = new List();
        var db = Database.Open("mPlan");
        var result = db.Query("SELECT * from Users where Username like '%" + txtSearch + "%'");
       try
       {
           foreach(var record in result)
            {
               searchResult result = new searchResult();
               result.Username = ["Username"].ToString();
               resultList.Add(result);
           }
           return resultList.ToArray();
       }
       catch
       {
           return null;
       }
  }}
Run Code Online (Sandbox Code Playgroud)

WebService.asmx:

<%@ WebService Language="C#" class="WebService" %>
using System;
using System.Collections.Generic; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net web-services asmx webmethod

2
推荐指数
1
解决办法
1万
查看次数

从Web方法获取标头

如何从jquery ajax调用获取标头属性。我正在标题中发送代码,因此我需要在web方法中阅读它:

$.ajax({
    type: "POST",
    url: url,
    data: data,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: success,
    error: error,
    headers: {
        'aaaa': "code"
    }
});
Run Code Online (Sandbox Code Playgroud)

c# webmethod

2
推荐指数
1
解决办法
5833
查看次数