为什么我不能在我的代码中使用 app_code 中的代码文件 asp.net c#

发布于 2024-12-09 00:49:40 字数 2680 浏览 1 评论 0原文

我正在开发一个 asp.net Web 应用程序,我的 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);
        }
    }
}

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

I am working on an asp.net web app, and I have few classes in my app_code, but for some reason I can't use any of them in my code. I tried using the same namespace, I tried without any namespace in both files, but nothing helps.

This is my page 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)
        {

        }
    }
}

And my code in the class:

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

Any idea what can be the problem?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的鱼塘能养鲲 2024-12-16 00:49:40

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

Go into the properties of the files, and change the Build Action to Compile

物价感观 2024-12-16 00:49:40

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

public 分部类 LinkedinMoreInfo : Authorization.LinkedInBasePage {

If your base page is name LinkedInBasePage, then you need to inherit from LinkedInBasePage instead of LinkedinBasePage

public partial class LinkedinMoreInfo : Authorisation.LinkedInBasePage {

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文