从静态方法访问QueryString/Session?

Kov*_*ovu 2 asp.net webmethod

我使用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 = Helper.StringHelper.AuctionDeatil_NoBidder;
            //lblHöchstesGebot.ForeColor = System.Drawing.Color.Red;
        }

        return new
        {
            valueTimer = timer,
            valuePrice = price,
            valueLastBidder = lastBidder
        };
    }
Run Code Online (Sandbox Code Playgroud)

Yur*_*ich 8

QueryString位于Request属性中.

System.Web.HttpContext.Current.Request.QueryString
Run Code Online (Sandbox Code Playgroud)

但会议在那里:

System.Web.HttpContext.Current.Session
Run Code Online (Sandbox Code Playgroud)


小智 7

出于兴趣,您为什么不直接将所需信息传递给Web方法?