“该名称在当前上下文中不存在”

本文关键字:上下文 不存在 | 更新日期: 2023-09-27 17:56:17

我收到以下错误;名称"请求"在当前上下文中不存在

using System;
using System.Web;
using System.Web.UI;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Microsoft.Exchange.WebServices.Data;
namespace Exchange101
{
    // This sample is for demonstration purposes only. Before you run this sample, make sure that the code meets the coding requirements of your organization.
    class Ex15_CreateMeetingOnBehalfOfPrinciple_CS
    {
        static ExchangeService service = Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());
        protected void Page_Load(object sender, EventArgs e)
        {
            var request = HttpContext.Current.Request.QueryString["source"];
            HttpRequest q = Request;
            NameValueCollection n = q.QueryString;
            if (n.HasKeys())
            {
                string k = n.GetKey(0);
                if (k == "one")
                {
                    string v = n.Get(0);
                }
                if (k == "two")
                {
                    string v = n.Get(0);
                }
            }
        }

是一个绝对的新手,并且已经研究了该错误,但对我可能缺少哪个程序集作为参考感到困惑。

“该名称在当前上下文中不存在”

问题可能在这里

 var request = HttpContext.Current.Request.QueryString["source"];
 HttpRequest q = Request;

您的变量名称是您正在使用的请求 BT

请求

将其更改为

 var request = HttpContext.Current.Request.QueryString["source"];
 HttpRequest q = request;

这将解决您的问题

更改此行:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS

对此:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS : System.Web.UI.Page

看起来您遇到的问题来自您应该从该类继承的属性。

如果你的意思是 HttpWebRequest,你应该包括命名空间 使用 System.Net;