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

时间:2014-04-02 03:47:20

标签: c# asp.net

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

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);
                }
            }
        }

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

3 个答案:

答案 0 :(得分:4)

问题可能在这里

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

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

将其更改为

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

这将解决您的问题

答案 1 :(得分:0)

更改此行:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS

到此:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS : System.Web.UI.Page

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

答案 2 :(得分:-1)

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