8

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

3
  • 2
    Are Authentication and Authorisation your "same namespace"? Commented Oct 10, 2011 at 20:44
  • Have you made sure App_Code is included in the project? And does it work if you move the classes from App_Code to your project's root directory? Commented Oct 10, 2011 at 20:45
  • @James I tried that too, it didn't work, same mistake, and yes it's included in the project. mellamokb, I did a typo with the 'Authorisation', but I tried with 'Authentication' too, I am getting the same error. ChrisF 'the type or namespace name could not be found...' Commented Oct 10, 2011 at 20:51

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks James, you are the man. If you have some time, can you explain how that change fixed my problem? Thanks a lot and have a good day.
You're very welcome. Setting the build action to Compile ensures that the code file is compiled into the build output.
I've reached my vote limit but good thinking, I wouldn't have thought of this! What are the purposes of the other Build Actions?
The build actions tell Visual Studio what to do with a file when a build is executed. This article explains the different build actions in detail: msdn.microsoft.com/en-us/library/0c6xyb66%28VS.90%29.aspx
0

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

public partial class LinkedinMoreInfo : Authorisation.LinkedInBasePage {

1 Comment

I don't see how this addresses the issue of accessing files in the App_Code directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.