未能加载从程序集“APP_ code”型 [英] Could not load type from assembly 'App_Code'
问题描述
我要创建在asp.net中自定义HTTP模块。 本文展示了如何做到这一点我按照步骤,这里是我的课从 IHttpModule的
公共类LanguageModule:IHttpModule的
{ 公共无效初始化(HttpApplication的情况下)
{
context.AcquireRequestState + =新的EventHandler(OnAcquireRequestState);
} 公共无效的Dispose()
{ } 公共无效OnAcquireRequestState(对象i_object,EventArgs的i_eventArgs)
{
HttpApplication的l_httpApplication = i_object作为HttpApplication的; //检查语言切换参数是否已经传递
VAR l_language =
l_httpApplication.Request.Params [Constants.SESSION_LANGUAGE]
VAR l_boolLanguageChanged = FALSE;
如果(l_language == NULL)
{
//如果没有发送语言参数,然后采取从会话语言
l_language =(字符串)l_httpApplication.Session [Constants.SESSION_LANGUAGE]
}
其他
{
//如果语言参数确实发送,则用户想要改变语言。
//我会确保我为了重定向到这个标签。
l_boolLanguageChanged = TRUE;
} //具有语言thand,让我们将它设置。
VAR l_culture =新System.Globalization.CultureInfo(l_language); Thread.CurrentThread.CurrentCulture = l_culture;
Thread.CurrentThread.CurrentUICulture = l_culture; //保存语言会话
l_httpApplication.Session [Constants.SESSION_LANGUAGE] = l_language; //检查我是否重定向
如果(l_boolLanguageChanged&安培;&安培;!l_httpApplication.Request.UrlReferrer = NULL)
{
l_httpApplication.Response.Redirect(
l_httpApplication.Request.UrlReferrer.AbsolutePath);
} } // OnAcquireRequestState
// -------------------------} //类LanguageModule
然后我注册了这个模块中的web.config
文件,像这样
<&的HttpModules GT;
<添加名称=LanguageSettingModuleTYPE =LanguageModule,APP_ code/>
< /&的HttpModules GT;
我也试过在的System.Web
像这样的标签
< system.webServer>
<模块runAllManagedModulesForAllRequests =真正的>
<添加名称=LanguageSettingModuleTYPE =LanguageModule,APP_ code/>
< /模块>
< /system.webServer>
文件 LanguageModule
被划归APP_ code文件夹
不过,我总是得到这个错误
未能加载从程序集APP_ code型。
块引用>解决方案从你的配置设置中删除
APP_ code
。在你的的web.config
它应该看起来像下面。即使你链接的MSDN文档,显示注册的方式相同。<&的HttpModules GT;
<添加名称=LanguageSettingModuleTYPE =LanguageModule/>
< /&的HttpModules GT;I want to create a custom HTTP module in asp.net. This article shows how to do it I followed the steps and here is my class which inherits from
IHttpModule
public class LanguageModule : IHttpModule { public void Init(HttpApplication context) { context.AcquireRequestState += new EventHandler(OnAcquireRequestState); } public void Dispose() { } public void OnAcquireRequestState(Object i_object, EventArgs i_eventArgs) { HttpApplication l_httpApplication = i_object as HttpApplication; // check whether the language change parameter has been passed var l_language = l_httpApplication.Request.Params[Constants.SESSION_LANGUAGE]; var l_boolLanguageChanged = false; if (l_language == null) { // if language parameter is not sent, then take language from session l_language = (string)l_httpApplication.Session[Constants.SESSION_LANGUAGE]; } else { // If language parameter is indeed sent, then user wants to change language. // I will make sure I tag this in order to redirect to. l_boolLanguageChanged = true; } // having the language a thand, let us set it. var l_culture = new System.Globalization.CultureInfo(l_language); Thread.CurrentThread.CurrentCulture = l_culture; Thread.CurrentThread.CurrentUICulture = l_culture; // save language to session l_httpApplication.Session[Constants.SESSION_LANGUAGE] = l_language; // check whether I have redirect if (l_boolLanguageChanged && l_httpApplication.Request.UrlReferrer != null) { l_httpApplication.Response.Redirect( l_httpApplication.Request.UrlReferrer.AbsolutePath); } } // OnAcquireRequestState //------------------------- } // class LanguageModule
Then I registered this module in
web.config
file like so<httpModules> <add name="LanguageSettingModule" type="LanguageModule, App_Code" /> </httpModules>
I tried also to register it under
system.web
tag like so<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="LanguageSettingModule" type="LanguageModule, App_Code" /> </modules> </system.webServer>
file
LanguageModule
is placed under App_Code folderBut I'm always getting this error
Could not load type from assembly 'App_Code'.
解决方案Remove the
App_Code
from your configuration setting. In yourweb.config
it should look like below. Even the MSDN document you linked, shows the same way of registering.<httpModules> <add name="LanguageSettingModule" type="LanguageModule" /> </httpModules>
这篇关于未能加载从程序集“APP_ code”型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!