4

Running under Server08 | IIS7. I have a website project and am in the habit of hand editing the Global.asax.cs at the deployed site many times in the past. Recently I've found that only the Global.asax is present and has only:

<%@ Application Codebehind="Global.asax.cs" Inherits="myDomain.MvcApplication" Language="C#" %>

There are simply no Global.asax.cs files present/visible for any of my active, functioning websites anymore.

I've checked here Global.asax can't find code-behind class and here where is the codes in Global.asax in mvc3? without getting anywhere. The second link contains the comment: 'That's because it's a compiled web application. You'll have to view it in Visual Studio as a project.'

But since my project has always been a website - and I've not converted it (intentionally) I'm puzzled by the changed behavior.

But when i step into VS12 and look at the context menu for the solution's WebProject it presents 'Convert to Web Application'. The sites' folder structures do not contain App_Data or App_Start. To my mind, these 2 fact establish at VS is treating the project as a website, why then, is the Global.cs compiled down to the /bin?

I'll close by repeating - I've hand edited these things in the past - I'm not positive but it's probably accurate to say that this is the first time I've tried to do so after installing VS12. And, coming to think on it harder - it's only recently that I've implemented the 'One Click Publishing' service so that could be coming into play.

verify? I'd like I need to edit a simple update without full re-deployment.

thx

Community
  • 1
  • 1
justSteve
  • 5,444
  • 19
  • 72
  • 137
  • When you had converted your application you couldn't change your code in .cs files anymore when application run. From now, your code-behinds are in your .dll and you should build your project and upload your .dll – Amir Sep 29 '12 at 08:20
  • I didn't convert the app. I'm making a point to establishing this as a web site project by saying that VS _offers_ the 'Convert to app' menu. – justSteve Sep 30 '12 at 11:48
  • If I'm reading this right I got another downvote on the question - anywhere I can see reasoning documenting why? Wondering if I frosted someone's cookies by downvoting the original proposed answer that 1) mis-read the question; 2) abandoned the topic. – justSteve Oct 09 '12 at 22:16

3 Answers3

4

I think the 'One Click Publishing' is most likely the culprit here. I created a sample Web Site project to experiment, and when I use the publish feature in Visual Studio, the files generated are indeed missing the Global.asax.cs file. Instead, a bin folder is created with a compilation called "App_global.asax.dll" even though it is a Web Site and not a Web Application. I am guessing this might be similar to what is happening for you as well.

If not, I found a link which might be useful to you in order to once again be able to edit a class on the server. Particularly, have a look at the second answer (the one not accepted as the best answer) to recreate a class file for the global code: Where is the Global.asax.cs file?

I tried this solution, and verified that the class file is editable on the server, and that it is dynamically compiled at run time (the modifications I made to the file worked immediately).

Hope this helps!

Community
  • 1
  • 1
mbnixon
  • 116
  • 4
0

After editing the global.asax you need to rebuild and upload the DLL to the bin folder. Otherwise, your changes will not take effect.

Mher Sarkissian
  • 131
  • 2
  • 5
  • Isn't that specific to Web Applications? Isn't the fact that I'm offered a menu item to 'Convert to Web Application' indication that I'm working with a website that has live access to Global.asax.cs. Again...that's the behavior for the last 4 years up until VS12 and/or one click publishing. – justSteve Sep 26 '12 at 00:35
0

You might be able to upload an web version of the global.asax that includes the code in that one file, which obviously does not require a .cs code behind. I used to do it with aspx files in an application but I have never tried it in the GLobal.asax file.

Carlos Martinez T
  • 6,458
  • 1
  • 34
  • 40