【问题标题】:why I can't use code files from app_code in my code asp.net c#为什么我不能在我的代码asp.net c#中使用来自app_code的代码文件
【发布时间】:2011-10-10 20:40:48
【问题描述】:

我正在开发一个 asp.net 网络应用程序,并且我的 app_code 中的类很少,但由于某种原因,我无法在我的代码中使用它们中的任何一个。我尝试使用相同的命名空间,我尝试在两个文件中都没有任何命名空间,但没有任何帮助。

这是我的页面代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkedIn;
using LinkedIn.ServiceEntities;


namespace Authentication
{
    public partial class LinkedinMoreInfo : LinkedinBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

还有我在课堂上的代码:

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;

using LinkedIn;

namespace Authorisation
{
    public class LinkedInBasePage : System.Web.UI.Page
    {
        private string AccessToken
        {
            get { return (string)Session["AccessToken"]; }
            set { Session["AccessToken"] = value; }
        }

        private InMemoryTokenManager TokenManager
        {
            get
            {
                var tokenManager = (InMemoryTokenManager)Application["TokenManager"];
                if (tokenManager == null)
                {
                    string consumerKey = ConfigurationManager.AppSettings["LinkedInConsumerKey"];
                    string consumerSecret = ConfigurationManager.AppSettings["LinkedInConsumerSecret"];
                    if (string.IsNullOrEmpty(consumerKey) == false)
                    {
                        tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
                        Application["TokenManager"] = tokenManager;
                    }
                }

                return tokenManager;
            }
        }

        protected WebOAuthAuthorization Authorization
        {
            get;
            private set;
        }

        protected override void OnLoad(EventArgs e)
        {
            this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);

            if (!IsPostBack)
            {
                string accessToken = this.Authorization.CompleteAuthorize();
                if (accessToken != null)
                {
                    this.AccessToken = accessToken;

                    Response.Redirect(Request.Path);
                }

                if (AccessToken == null)
                {
                    this.Authorization.BeginAuthorize();
                }
            }

            base.OnLoad(e);
        }
    }
}

知道可能是什么问题吗? 提前致谢

【问题讨论】:

  • AuthenticationAuthorisation 是你的“同一个命名空间”吗?
  • 您确定 App_Code 包含在项目中了吗?如果将类从 App_Code 移动到项目的根目录,它会起作用吗?
  • @James 我也试过了,它没有用,同样的错误,是的,它包含在项目中。 mellamokb,我在“授权”上打错了字,但我也尝试过“身份验证”,我得到了同样的错误。 ChrisF '找不到类型或命名空间名称...'

标签: c# asp.net visual-studio-2010 app-code


【解决方案1】:

进入文件属性,将Build Action改为Compile

【讨论】:

  • 谢谢詹姆斯,你就是那个人。如果你有时间,你能解释一下这个改变是如何解决我的问题的吗?非常感谢,祝您有美好的一天。
  • 不客气。将构建操作设置为Compile 可确保将代码文件编译到构建输出中。
  • 我已经达到了我的投票上限,但是我的想法很好,我不会想到这个!其他构建操作的目的是什么?
  • 构建操作告诉 Visual Studio 在执行构建时如何处理文件。本文详细解释了不同的构建操作:msdn.microsoft.com/en-us/library/0c6xyb66%28VS.90%29.aspx
【解决方案2】:

如果您的基本页面名称为LinkedInBasePage,那么您需要从LinkedInBasePage 继承而不是LinkedinBasePage

public partial class LinkedinMoreInfo : Authorisation.LinkedInBasePage {

【讨论】:

  • 我不明白这如何解决访问App_Code 目录中的文件的问题。
  • @sonnychiba 感谢您的帮助,以下解决方案解决了我的问题。祝你有美好的一天。
猜你喜欢
  • 1970-01-01
  • 2015-06-12
  • 2015-11-02
  • 1970-01-01
  • 2016-02-19
  • 2017-11-23
  • 1970-01-01
  • 2011-04-13
  • 2011-09-23
相关资源
最近更新 更多