Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to QueryString / Session from a static Method?

I use ASP.Net and a static WebMethod / PageMethod to do some async work. My question is how to access my queryStrings and Session variables here?

I tried "HttpContext.Current" and a lot of information is available here, but not my QueryString nor my Session and I don't know why.

 [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
        };
    }
like image 597
PassionateDeveloper Avatar asked Feb 04 '26 12:02

PassionateDeveloper


1 Answers

The QueryString is in the Request property.

System.Web.HttpContext.Current.Request.QueryString

But the Session is in there:

System.Web.HttpContext.Current.Session
like image 137
Yuriy Faktorovich Avatar answered Feb 07 '26 04:02

Yuriy Faktorovich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!