2013-02-02 60 views
0

可能重複:
Why can’t it find my BasicAuthenticationModule?爲什麼它不會找到我的模塊?

我試圖創建自己實現一個基本的身份驗證。

我有存儲在我的solution\Modules和其命名空間BasicAuthenticationModule.cs是:

namespace Web_API.Modules 
{ 
    public class BasicAuthenticationModule : IHttpModule 

香港專業教育學院把它添加到我的web.config這樣:

<system.webServer> 
    <modules> 
     <add name="MyBasicAuthenticationModule" type="Web_API.Modules.BasicAuthenticationModule, BasicAuthenticationModule" /> 

我得到這個運行時出現以下錯誤:

Server Error in '/' Application. 

Could not load file or assembly 'BasicAuthenticationModule' or one of its dependencies. The system cannot find the file specified. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'BasicAuthenticationModule' or one of its dependencies. The system cannot find the file specified. 

我在做什麼錯在這裏?

+1

如何爲您的程序集命名磁盤上擁有你的班級? – rene

+0

@rene請問您能具體說明嗎? – Jason94

+1

保存你的類的項目有一個輸出文件名,因爲它是在dll中編譯的。我懷疑dll的名稱不是BasicAuthenticationModule,但可能是Web_API或類似的東西。 – rene

回答

3

您似乎已經爲模塊指定了錯誤的程序集名稱。當你寫:

type="Web_API.Modules.BasicAuthenticationModule, BasicAuthenticationModule" 

這意味着所謂的BasicAuthenticationModule組件內加載Web_API.Modules命名空間中一個名爲BasicAuthenticationModule類。您定義此類的項目是BasicAuthenticationModule嗎?我猜不會。這就是爲什麼ASP.NET無法加載你的模塊。您應該指定用於定義此模塊的正確程序集名稱。

例如,如果你的ASP.NET MVC應用程序被稱爲MvcAPplication1的定義可能是這樣的:

type="Web_API.Modules.BasicAuthenticationModule, MvcApplication1" 

類型屬性的格式是這樣的:

type="Namespace.ClassName, AssemblyName" 
+0

現在即時獲取'值不能爲空。參數名稱:typeName'在我的模塊中的以下內容:'string provider = ConfigurationManager.AppSettings [「Web_API.Modules.BasicAuthenticationModule.AuthProvider」]; 類型providerType = Type.GetType(provider,true);' 提供程序爲空,我必須在某處定義它嗎? – Jason94

+0

好吧,您似乎已經在指向某種運行時類型的web.config文件中定義了一些'Web_API.Modules.BasicAuthenticationModule.Auth Provider'設置。確保它也遵循''Namespace.ClassName,AssemblyName「'模式,並且此類型實際存在。很難說,但至少現在你的模塊被加載並執行了,這是你的原始問題。 –

+0

我採取了一個瘋狂的猜測,它的工作原理... – Jason94

相關問題