2011-10-10 48 views
8

我正在研究一個asp.net web應用程序,並且我的app_code中有幾個類,但出於某種原因,我無法使用任何他們在我的代碼中。我嘗試使用相同的命名空間,我試圖在兩個文件中沒有任何命名空間,但沒有任何幫助。爲什麼我不能在我的代碼中使用app_code中的代碼文件asp.net c#

這是我的網頁代碼:

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

任何想法可能是什麼問題? 在此先感謝

+0

你會得到什麼錯誤? – ChrisF

+2

'Authentication'和'Authorisation'是否是「相同的命名空間」? – mellamokb

+0

您是否確定App_Code包含在項目中?如果將類從App_Code移動到項目的根目錄,它是否工作? – James

回答

10

進入到文件的屬性,並更改Build ActionCompile

+0

謝謝詹姆斯,你是男人。如果你有一些時間,你能解釋一下這種改變如何解決了我的問題嗎?非常感謝,祝你有美好的一天。 – Laziale

+0

非常歡迎。將構建操作設置爲「編譯」可確保將代碼文件編譯到構建輸出中。 –

+0

我已經達到了我的選票限制,但思路很好,我不會想到這個!其他構建行爲的目的是什麼? – James

0

如果你的基本頁面是名LinkedInBasePage,那麼你需要從LinkedInBasePage繼承,而不是LinkedinBasePage

public partial class LinkedinMoreInfo : Authorisation.LinkedInBasePage {

+0

我不明白這是如何解決訪問'App_Code'目錄中文件的問題。 –

+0

@sonnychiba感謝您的幫助,下面的解決方案解決了我的問題。祝你有美好的一天。 – Laziale

相關問題