简体   繁体   English

Global.asax不起作用

[英]Global.asax not working

I'm planning to utilize the global import for System.Data package. 我打算利用System.Data包的全局导入。 After I added the 我加了之后

<%@ Import Namespace="System.Data" %> 

in the markup of global.asax 在global.asax的标记中

In one of my class I removed 'Using System.Data' on top of the code. 在我的一个课程中,我删除了代码之上的“Using System.Data”。 I built the global.asax and the class. 我构建了global.asax和类。

But instead of built successful, I received error 但我没有建成功,而是收到了错误

The name 'CommandType' does not exist in the current context. “CommandType”名称在当前上下文中不存在。

I think that you misunderstand what global.asax does. 我认为你误解了global.asax的作用。

It doesn't provide for global Import/Using statements. 它不提供全局导入/使用语句。

Read up on it here and even better a Stackoverflow answer here 这里阅读它,甚至更好的Stackoverflow答案在这里

Global.asax allows you to handle application/session lifecyle events. Global.asax允许您处理应用程序/会话生命周期事件。

You will need to include your Import Namespace in the files that you are using calls to the System.Data namespace 您需要在使用System.Data命名空间调用的文件中包含Import Namespace

I think you might need to import the System.Data.SqlClient namespace too, assuming that's a command object it's failing on. 我认为您可能还需要导入System.Data.SqlClient命名空间,假设它是一个失败的命令对象。

EDIT 编辑

If you want certain namespaces available to all pages, try adding them in the web.config instead: 如果您希望所有页面都可以使用某些名称空间,请尝试在web.config中添加它们:

<pages>
    <namespaces>
        <add namespace="System.IO" />
        <add namespace="ProjectName.Classes" />
    </namespaces>
</pages>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM