Why is global.asax missing from a Website Project - asp.net

A couple of questions regarding the role of global.asax:
Why is it not included in the Website Project in Visual Studio? Are there other ways of achieving the same functionality without this file?
If I would create a Web Application project, as far as I remember, a global.asax file would be created. If I were to delete it, would the project run?
I tried to look for some explanation regarding the global.asax compilation but didn't find any info about this.. would appreciate help/links. :)
Thanks!

An ASP.NET site can run without the global.asax file. Here is a question which talks about alternatives of global.asax file.
Even if you delete a global.asax file your site will work.

Globax.asax is not required by ASP.NET for a website to run. It is, however, very useful for application-level functionality (like unhandled exception logging).

You can add Global.asax to the website project and it will work fine.
Global.asax is not added by default for web applications. If you have it, you can delete it without problems.
Be careful to include the .compiled files when deploying the website or else the events in Global.asax will not fire.

It sounds like you are familiar with Web Application Projects, now see a Web Site "project" and wonder what's going on. In any case, I'll answer as though that were true. ;-)
In Visual Studio 2005, Microsoft introduced Web Site "projects", which are not projects - they're just directory structures on a local disk, FTP site, etc. They do many things differently from Web Application Projects, and can therefore be confusing (especially if you're like me, trying to answer people's questions, not knowing which they are using).
With Visual Studio 2005 SP1, they restored Web Application Projects. If that's what you're more familiar with, then I suggest you use them. They're real projects, just like they always were.
And, BTW, there will be a global.asax, just like there used to be...

Related

CI / CD pipeline for legacy ASP.NET Web Forms application

I am taking over a legacy ASP.NET Web Forms application written a long time ago. The application does not come with a .csproj file or a VS .sln file. All DLL libraries are simply added to the bin folder and referenced directly in code. All CS classes are added to the app_code folder and referenced in code.
We are trying to integrate this site to make use of CI / CD pipelines but it has been very challenging. Part of it is because we cant make use of MSBuild because we don't have a project file or a solution file.
I was wondering if anyone has been in a similar situation before. What would be the best way to create a project and / or solution file for this? Do we need to have both a project file and a solution file? Any guides out there you can point to on how to do this?
I hope my question is clear. Thanks in advance!
The application does not come with a .csproj file or a VS .sln file
That is normal for a asp.net web site. No sln, or project files are required.
Of course that means you do NOT open the site by using open project, but open the site by using open web site. As such, no csproj or even a project (sln) file is required, or should even exist.
All DLL libraries are simply added to the bin folder and referenced directly in code
Again, that's quite normal for web site.
For a web site "application", then references to external libraies and .dll's (assmeblies) is much like desktop. You add these refrences. then at deploy time, visual stuido will build, compile, and move all the .dll's into the bin folder for you. And you even have options to "merge" such .dll's into one .dll at publish time.
At this point in time, if you can open the site site, view a web page, and then say right click, and view code, then you are in great shape.
However, it is ALSO possible that your web site folder is the RESULT of a asp.net web site "application". If that is the case, then the web site will NOT have the code behind, since Visual studio did the compile. When you use a asp.net web site (not a asp.net web site application), then both the markup pages, and the code behind pages should exist. This ALSO means that the web site (IIS) does the compile of code, and NOT visual studio.
so, the only detail you need to determine?
Does the web site have BOTH the markup pages, and ALSO has the source code (code behind) pages? If you do not have the code behind pages, then you don't have a web site, but have the "results" of a web site application publish. This means you don't have the code behind (source code).
But, opening a web site from visual studio does not need nor require a project file, nor does it require sln file.
so, I guess the base question (that will quite much answer all of the above points and questions?
do you see + have the code behind pages on that site? Since if you do not, then you have to go find and get the original project used to publish that web site application, and without as such, you not only missing the source code, but all of the references etc. that are saved in the project file(s).
What would be the best way to create a project and / or solution file for this?
Gee, if this is a web site and not "application", then you may well not want to do this (at least not yet). There are quite a few advantages of keeping and using a web site as opposed to a web site application, and one issue will be setup of all the references.
Also, web servers tend to be far more tolerent of accepting a web site, then a web site application. (for example, it boatloads easier to copy or ftp a web site to a sub site in a folder on the web server.
If the main startup page is the main page of the web site, then it without question a lot easier to say convert, and open the folder as a project, and thus the sln file will be created. However, quite a few assumptions will have been made based on "application" vs non application, and if that's how the system was setup, then little advantages exist to now try and convert to a web application.
The other huge advantage? with a web site, you can modify one line of code, save, and you are done.
With a web site application, you change just one line of code, and you now have to re-publish the WHOLE site. So, while I without question prefer the application road? You noted in your post that you want to keep agile development, and if that is your goal, then hands down keeping this as a web site is a far better choice. You can change one line of code, save, and if that page + code is moved to the server, you are done.
so, a application is far more formalized, but quite much kills the agile development goal you noted in your post.

db4o on shared hosting with asp.net MVC

I'm wanting to use DB4o on an asp.net MVC project i'm working on but wondering if anyone
has got this working on shared hosting plan, have contacted discountasp and asked them and they said go to the forum
as they were not sure if they supported it or not or any configuration that would be needed.
but the forum wont let my post on because its all filtered to only show comments they like the look of?
anyone had any joy with this with another host and one that runs asp.net MVC as it should be run?
much appreciated
ta
I'm not familiar with the framework, but it seems that you can just place the DLL in the bin folder and you should be set. I've done tons of projects with MVC and the same method of placing the DLL in the bin folder and worked without issues. The host I use is ReliableSite...they're cheap and don't charge $10/mo for a SQL Server database like DiscountASP does.

Detecting Changes in an ASP.NET Web Site

The ASP.NET framework does a very good job of detecting when a file has changed and recompiling that file etc. I would like to be able to hook into that update process. Is this at all possible?
I might want to do this as part of an initiative to try and version web sites developed as Web Site projects, versus Web Applications, where the version is easily found in statically deployed assemblies. If I my be misdirecting my energies as there are already better way if versioning web sites, I'd still appreciate some pointers.
I don't know if you can hook into that logic at all - perhaps you could add your code to Application_OnStart as this method will fire when ASP.NET recycles the AppPool and restarts the website.
Have you tried Web Deployment projects?
Scott Gu has a blog post.
You can use ASP.NET SignalR to do it, It's real-time web for .NET
Have you tried developing a separate module for ASP.NET that keeps track of last change?
This might put you on the right path (might -- I haven't tried this).
http://www.codersource.net/csharp_iis_metabase.html (dead link)

Debug .asp pages with visual studio 2005

I'm migrating a website made in classic asp to asp.net, but the asp.net dev server doesn't handle .asp pages.
Is it possible to make it run .asp pages? Maybe a custom httphandler for .asp?
thanks!
Are you running Winxp with IIS installed? If so, here's what I do: hit the asp pages in the browser using your local IIS, and then open the folder where the ASP pages reside as a website project in VS. Go to the Debug menu, choose Attach to Process, and then look for the dllhost.exe process that is running under the IWAM_MACHINENAME user. You also have to make sure the you have setup the virtual directory to allow ASP server-side debugging. After attaching to that process, you can set breakpoints, etc. as usual.
The last time I had to debug asp pages I found it was easier to insert a bunch of Response.Write()'s. If you cant find a way to do it in VS, then this may help.
Unfortunately you will have to use traditional (or arcane!) methods to debug your asp pages in VS2005 (i.e. alert(), response.write() etc.)
Possibly not what you want to hear, but vs2005 doesn't support this. It was re-added into vs2008. Perhaps one of the free vs2008 express edtions might get you out of this hole?
In addition to the answer provided by patmortech I would recommend that if you are testing a mixed tech site you attach to aspnet_wp to debug the .NET portions of the app. This is also true if your app uses third-party ISAPI filters.
The Cassini server is good for pure .NET only.

ASP.net: Website or web application project

Is there any difference between website and web application project? What if you are working on a project that is sort of hybrid of site and application? which project should you chose?
I'ld go the newer Web Application project (always, regardless of the size of the project).
There is nothing to lose and everything to gain with using the Web Application Project (you cannot say this about using the "website" only).
The official list of differences are here:
Use Web Application Projects when you
Need to migrate large Visual Studio.NET 2003 applications
Need to
control names of output assemblies
Need stand-alone classes to
reference page and user control
classes
Need to build a Web
application using multiple Web
projects
Need to add pre-build and
post-build steps during compilation
Use Websites if you:
Need to generate one assembly for each page.
Prefer single-page code model to code-behind model.
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and then simply refresh the page in the browser).
Want to open and edit any directory as a Web project without creating a project file
#Mehrdad's link here is essential if you want to know more http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5
As for which project to choose, I would go with the Web Application Project, regardless of size. Having all of your code behind compile down into a single DLL is a major benefit for maintenance and security on the hosting end. I know there are precompile options for web site projects, but they seemed like more trouble that it was worth for me.
I know that the IIS filters are in place to prevent users from accessing your .vb or .cs files, but it still makes me a little leery.
But more important to this is the nice fact that if you make a bunch of coding changes, or maybe add some classes and change the processing logic, the only thing you have to merge up is the compiled DLL and nothing else. Similarly, if you do a few UI changes (say change the stylesheet or position of a few controls), you don't have to worry about recompiling the application, you simply bring over the update .aspx page and you're done.
Take a look:
http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5
http://forums.asp.net/p/1300026/2538628.aspx
I'm used to create websites when I want to create a new webapplication.
My current project had some problems on compiling, so I switched to a webapplication project. The step isn't very hard. Visual Studio helps you to change all necessary lines.
Refer to the links in the post:
http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx
Anthony :-)

Resources