ASP.NET - Change from Web Application Project to Web Site Project - asp.net

I am new to Visual Studio and ASP.NET. I have a MyClass.cs file under App_Code directory, but could not able to run the function in the class file. Keep getting this error:
The name 'MyClass' does not exist in the current context
I know that code works fine since I posted the codes and others confirmed it works, but I am still receiving the error above.
I read alot more threads on the NET and somes indicated that problem is using Web Application Project instead of Web Site project, which the class file would not compile. I am not sure if I've created it under Application Project we Web Site project.
How can I tell that my site is running under Web Application Project or Web Site Project? and How can I change it to Web Site Project so my class can be recognized.
Thanks in advance,

Related

Difficulty with Converting a WebSite to Web Application and Testing

This is not as straight forward as I had hoped.
I created a Web Site project on my development machine using the Visual Studio C# template for a WebSite Project. (Visual studio 2010 .net 4.0). The project name is C:\Nova5\WebSite3. It consists solely of:
the Bin subdirectory
Nova.svc file
web.config file
It has been tested to run correctly by:
Setting the website as the startup project, then
Run Debug-->Start Debugging
When tested, the NovaDataService information page is correctly displayed. It also correctly works when used through my client project.
I followed the recommended procedure described at
Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio to covert the Web Site to a Web Application.
I now have the following problems and/or difficulties:
If I use the recommended procedure for testing the web site:
-- File | Open | Web Site
-- Build Web Site -- Start Debugging
I get the Error: The type 'Nova5WCFServiceLibrary.NovaDataService', provided as the Service attribute value in the ServiceHost directive, or provided in
the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Since, I think, the WebSite does work, I skipped this error and moved on to the next part of the article. The next issue (?) is there is no App_Code file in the WebSite. Is this necessary? If it is necessary, how should I create it? Or do I need to create another WebSite project from its template just to have it?
I did not copy the Nova.svc nor the web.config from the WebSite to the Web Application as none of the references I read indicated to do so. Should I copy these files to the Web Application as well?
I now used the "Convert to Web Application" on the Web Application project and recompiled the solution. Everybody is happy. No errors reported. So how do I now test the Web Application project on my development machine (which also has the client application) ?
TIA

Old Asp.Net Web Site Project - No Project file?

So I have an Asp.Net website that i'm responsible for. I'm having a build issue, that as far as I can tell, may be either MacAfee or some other random cause.
But thinking back, I want to say the problem started when I added a "Test.aspx" form to the site, did some testing, then removed the Test.aspx form from the site.
I'm using TFS 2010 as my source control as well. Which I don't know if it applies or not.
My question is, is there some hidden location where all files to be included in publishing a website is maintained?
Is there a Project file for a Web Site app and if so where is it?
I've built the site using MSBUILD and notice some metaprj project file in the output but I can't seem to find any such file.
Web Site apps aren't meant to be built into a dll file. There is a conversion wizard to make it a web project but it doesn't always work well. My advice would be to continue to work with it as a Web Site app. The code files are compiled at at runtime on first use. You can run from Visual Studio or setup a site in IIS. Nothing is hidden in a Web Site app and there is no project file. So, you shouldn't have a build issue because you shouldn't be building. Try to run the app as is and if you get an error let us know what the specific message is.

Have to specify Assembly name for all class references

VS 2010, .NET 4.0, VB, EF 4.4
I was having issues deploying my web application to the server... was getting the error "Could not load type " when I tried running it on the server. Googling around I also found that my Web App should not have an "App_Code" folder (copied over shared but of code from other corporate Web Sites). So I moved all the classes from App_Code to a folder off the root ("BLL" - also the namespace of our code library).
Now when I run the app in the VS IDE I'm getting the error "Configuration Error. Could not load type 'BLL.Roles'" coming from the load of the web.config. If I add the assembly name of the app to the front of the "BLL.Roles" > "appName.BLL.Roles" I get past this line and error out at the next reference to "BLL".
I've Cleane and Rebuilt my project.
Why are my classes not getting recognized as part of the app?
I could be wrong but i believe because you are using a Web Site and not a Web application you can only access classes that live in the App_Code Folder. If you are working with a Web Application you can access classes no matter what folder they live in. In that case you might have to move your files to a new project that is under a Application format and not a Web Site format. I would try to move your files to a Web Application project.

Publishing web apps and websites

I understand that references are stored in the project (vbproj) file for ASP.NET web applications and the Web.Config (http://msdn.microsoft.com/en-us/library/37e2zyhb%28v=vs.71%29.aspx) for websites.
I have recently converted a website into a web application. I notice now that the web application will publish (using the Publish option) even if the version information is incorrect in the Web.Config, then when accessing the web application through a browser I get an error.
I was unable to Publish a website if the version of an assembly in the Web.Config was incorrect.
I read that web applications are precompiled (before publish) whereas websites are compiled the first time the website is accessed through a browser.
Therefore, I believe what I have said should be the other way around i.e. I should be able to publish websites with an incorrect version in the Web.Config (because they are not compiled) and I should not be able to publish a web application.
What am I missing?
After some further research; I have discovered that ASP.NET web applications are built using MSBuild and ASP.NET websites are built using ASPnet_Compiler.
ASPnet_Compiler looks in the Web.Config for referenced assemblies (add assembly tag) at build time, whereas MSBuild looks in the project file (vbproj) at build time.
Web applications are deployed without the vbproj. I believe the project file is used for linking. Therefore at runtime a web application uses the information in the Web.Config to identify assemblies to look for in the local bin folder and then the GAC (for aspx pages only)i.e. namesapces still have to be manually imported into the code behind partial classes.
If anyone has any comments or better answer then please post.

Turning a precompiled web app to a 'normal' web app

I've got a quick question about precompiled web apps:
I've recently took over a project done by someone else, which is a precompiled web app. This means that it has no App_Code folder, of course. Due to the nature of this project I would like to put my code on the server anyhow.
I can't just add the code, because I'll get an Exception stating that the App_Code folder isn't allowed because it's a precompiled web app. If I remove the file 'PrecompiledApp.config", then my application crashes.
So what are the correct steps in turning a precompiled web app to a compile-on-demand webapp?
Thanks for the help.
I can get this working in VS2010.
Go to your web app settings and select the Package / Publish Web tab. There's a drop down that's probably defaulted to 'Only files needed to run this application'. If I use this it just publishes the compiled DLLs to the server and the web files, but none of the code.
If I change this to 'All files in the project folder' then I get everything - all the C# code for my controllers, for example.
Of course whether you would want your production code on a server is a different question, and you also get all the VS solution files and stuff like that too so it looks quite messy.

Resources