简体   繁体   中英

Global.asax not working

I'm planning to utilize the global import for System.Data package. After I added the

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

in the markup of global.asax

In one of my class I removed 'Using System.Data' on top of the code. I built the global.asax and the class.

But instead of built successful, I received error

The name 'CommandType' does not exist in the current context.

I think that you misunderstand what global.asax does.

It doesn't provide for global Import/Using statements.

Read up on it here and even better a Stackoverflow answer here

Global.asax allows you to handle application/session lifecyle events.

You will need to include your Import Namespace in the files that you are using calls to the System.Data namespace

I think you might need to import the System.Data.SqlClient namespace too, assuming that's a command object it's failing on.

EDIT

If you want certain namespaces available to all pages, try adding them in the web.config instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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