ASP.NET web site can't see .cs file in App_Code folder

南笙酒味 提交于 2019-11-30 06:58:12

By default websites don't compile .cs files. You will need to do a few different things.

  1. Set each class file to "compile" in the properties for that class file. You can see this option by clicking the class file, viewing the properties in the properties explorer window, and changing the Build Action dropdown list to "Compile."

  2. If the above doesn't help, remove the class from the app_code and drop it in the root folder.

Do you have app_code folder it the root folder of the web application (not only folder or virtual folder). It seems that Asp.NET can't see app_code folder.

Conent and compile options are available only in WebApplication project.

I asked this question before starting an account, otherwise I'd edit it.

I have the same error after:

  1. Checking that I have a Web Site, not Web Application, thus no Compile/Content properties for the .cs file.

  2. Checking position of the App_Code Folder. I tried putting GridView.aspx under root as well as in its own folder, same error. \ \App_Code DataAccess.cs \App_Data \GridView GridView.aspx Web.config

  3. Moving the class from App_Code to root. Same error.

  4. This last I thought would work, but didn't. Used the Publish Web Site feature to upload precompiled code. I could see that it was now DataAccess.dll in the bin folder, and there was a PrecompiledApp.config file in the root. Same error.

UPDATE: solved it: the folder structure on the server was like the local one, but I had everything in a subfolder... App_Code and App_Data must be in the root of the server.

You probably need to compile your application before deploying it. At the moment ASP.NET has no way of knowing about .cs files that aren't attached to .aspx/.ascx files. I'd recommend looking at Web Deployment Projects or using the Visual Studio 2010 "Publish" option. Scott Guthrie gives a better summary than I ever could here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!