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

5
我遇到了以下错误: 当前上下文中不存在“Request”名称。
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);
                }
            }
        }

我是一个完全的新手,已经研究了这个错误,但是不知道我可能缺少哪个程序集作为引用。


你是否在引用 System.Web? - Ben Aaronson
2
哦,没错,mellamokb可能是对的。在C#中,变量名是区分大小写的。 - Ben Aaronson
你有一个名为 Page_Load 的类,但它本身不是一个 Page 对象,这很令人困惑。你是从某个示例项目中复制了这段代码吗? - mellamokb
这是通过EWS API向Exchange日历添加会议的示例。我想修改代码,以便去掉电子邮件地址和密码的控制台输入。我希望能够从另一个页面调用此页面并传递变量。 - user990016
我已经修改了您的标题。请参见“问题标题中是否应包括“标签”?”,其中共识是“不应该”。 - John Saunders
显示剩余6条评论
3个回答

5
问题可能出在这里。
 var request = HttpContext.Current.Request.QueryString["source"];
 HttpRequest q = Request;

你的变量名为request,但你正在使用Request

请将其更改为

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

这将解决您的问题。

甚至可以这样写: "HttpRequest q = HttpContext.Current.Request.QueryString["source"];" - Polyfun

0

将这一行改成:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS

转换为:

class Ex15_CreateMeetingOnBehalfOfPrinciple_CS : System.Web.UI.Page

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


-1
如果你是指HttpWebRequest,你应该包含命名空间using System.Net;

HttpRequest不就是存在于System.Web中吗? - Ben Aaronson
2
http://msdn.microsoft.com/en-us/library/system.web.httprequest%28v=vs.100%29.aspx 说的是 System.Web 命名空间。 - Ben Aaronson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接