Various common problems in Asp.net with Global.asax

zequion 446 Reputation points
2023-05-12T03:26:21.9833333+00:00

I use only one machine in local with Windows 11 and the latest version of VS and asp.net with .net 4.8.1. In VS I use the option "use default web server".

1.- To be able to do tests starting from Application_Start() the only thing that works is to restart the computer. No other known option works. There is no use stopping iis, nor saving in Web.config or Global.asax. I reboot every few minutes. Someone has done things very badly decades ago and the others have not let them know, on the contrary, there are many people who come together to make excuses instead of asking for the bugs to be fixed.

2.- How do you fire the damn Application_Init() event of Global.asax. There is no way.

3.- In the Application_Start() event it is almost never possible to stop to debug but on occasion it is possible. Why have they been making excuses for decades instead of solving it?

4.- VS takes a long time to display the web page because it keeps connecting to the IIS server.

5.-They have not improved Sql server for decades.

6.- The problem that I have been trying to solve for 2 weeks, when before installing windows 11 it worked fine, is that once the web has appeared, session and application close automatically and even start again without touching anything and I do not have any command to close session neither application and in iis there is only a reference to the web.

<%@ Application Language="C#" %>
<%@ Import Namespace="localhost" %>
  
<script runat="server">
public static bool Application_Init    = false;
public static bool Application_Start = false;

public class Global : System.Web.HttpApplication
{   public override void Init(){ Application_Init = true; }
}

void Application_Start(object sender, System.EventArgs e){ Application_Start = true; }
void Session_Start(object sender, System.EventArgs e)
{  // Stop Whith DEBUG and consult Application_Init & Application_Start.
}
</script>
Developer technologies | ASP.NET | Other
{count} votes

5 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-05-12T21:23:03.35+00:00

    To refire the app init event you just recycle the app pool, and make a request. Maybe you are trying to debug. This hard as usually the init event has completed before the debugger has attached. Just add a sleep statement to delay long enough to attach.

    1 person found this answer helpful.

  2. Albert Kallal 5,586 Reputation points
    2023-05-12T18:24:05.5533333+00:00

    Hum, a few things:

    As noted, what kind of project (asp.net web site, OR a asp.net web site application - that will matter here).

    Is this a mvc site, or a asp.net webforms site? (again that matters).

    and your inti event? Gee, I don't use it, but you can't (to my knowledge) just out of the blue make up parameters for that event stub, you have to match the internal defined one if you over ride.

    So, then this:

            public override void Init() 
            
            {
                Debug.Print("init event");
            }
    
    

    So, if I try to add some parameter's to the above, my project does not even compile.

    Also, you don't mention/note HOW you running + testing the site. Are you connecting to full pop IIS, or are you developing local with IIS.

    Again, this matters, since if you connecting to a full pop production server, then often the time it takes for the debugger to connect, and it can miss some of those "faster" starting events. So, app_start might well trigger before the debugger gets attached.

    I do find however developing local with the default IIS "express", then that's not a issue (ie: I am 100% free to just use vs and a break point).

    However, as noted, it depends on your setup. However, in place of waiting for the vs debugger to connect, then you can just put a break line in the code.

    eg this:

            public override void Init() 
            
            {
                Debug.Print("init event");
                Debugger.Break();    
            }
    
    

    To be fair, in the last 10 years, I can't think of a time when I wanted a break-point in application_init or _start, but the above is a great approach to that issue. Those are VERY early events - so forcing a break point as per above will help. And as noted, I don't think you can just "out of the blue" decide to add that parameter you have to Init() event - it don't have one!!

    VS takes a long time to display the web page because it keeps connecting to the IIS server.

    Are you working on your dev box, or trying to connect over a network to IIS? I would just run 100% local - use the default edition of IIS express that is automatic installed along with Visual Studio. That should shorten your startup delays down to sub 1 second, or even say 4 seconds tops.

    They have not improved Sql server for decades.

    I respectably disagree. I can grasp that you are frustrated, but THEN dumping on SQL server as a result? That's 2 different issues here.

    The new "data paging" options in sql server are nice (that allows REAL data paging, so you can say build a query against a table with 1 million rows, but THEN say only give me the first 20 rows - so for high speed data paging in a gridview or what not? A Fantastic feature been added to SQL server - one of my favorite's.

    And the so "time travel" or so called "temporal tables" option is a great way to introduce reporting for a given month or "time travel" back to a given point in time - an amazing feature. So, you can say report month revenue form a year ago, but such data and revenue and totals might be changing over time. This "time travel" ability in SQL server has a lot of interesting use cases.

    And XML features also been improved.

    once the web has appeared, session and application close automatically

    Well, un-handled errors do trigger a app_pool restart. But without more details, it hard to guess the issue.

    I'm running vs2022, SQL server express, IIS express on my laptop, and I find performance just excellent. A site appears in about 3 seconds in most cases from having hit f5, and some sites a bit faster - it tends to depend on how many extra packages (nuget) I added to the project. A fresh out of a box new webforms site?

    It comes up in less then 1 second from hitting f5.

    it does seem over time as I chop away at code, then start times do seem to increase - and this is especially the case for "web site applications" as opposed to just a web site

    So, a few suggestions:

    What .net version, what kind of application matters here.

    Are you working on a copy, or connecting to some production IIS server - I find connection to IIS as a debug session always been slow.

    So, solution is to setup your dev computer to have the database, IIS (express), and vs on the same computer - you get great performance that way.


  3. zequion 446 Reputation points
    2023-05-16T10:40:38.37+00:00

    If you have projects in Asp.net, you have been assigning values to iis that are saved in web.config automatically. When installing windows 11, iis has the original values that don't match the ones in the projects. When finding a difference in one of the values, Session and Application close without giving any explanation and I spent 2 weeks looking for the problem. Now we know.

    0 comments No comments

  4. zequion 446 Reputation points
    2023-05-16T11:03:32.66+00:00

    init() is an event that is executed multiple times before an event occurs and it is not the Application_Init() event, which I have not been able to reproduce and am beginning to doubt that it exists.

    I can't use the just-in-time debugger because it starts out saying I have to run it as administrator, which I do, then I get a lot of error messages saying it couldn't load modules, and finally, whatever I click, it doesn't do anything. I have read that this debugger is only to be used from executables, not from VS.

    You talk about working locally but I have tried to activate iis express and that option does not appear in VS 2022. In the examples that I have found on the internet, images of VS 2019 appear with options that I do not have. In "Properties", "Startup Options", I can only activate "Use default web server".

    As I said, sometimes you can stop execution at Application_Start() but usually it only stops at Session_Start(). Why sometimes yes and not always?

    On Sql server I have found many serious flaws in T-SQL, which I have demonstrated, for Spanish and Catalan languages and Microsoft has finally recognized it in writing and for years they have told me that "they are going to work on it (lie)".

    After 2 weeks I have found a serious bug in Asp.net that I explain at: https://learn.microsoft.com/en-us/answers/questions/1284793/all-events-are-executed-2-times

    Answered? I think so.

    0 comments No comments

  5. zequion 446 Reputation points
    2023-05-16T21:36:00.4033333+00:00

    init() is an event that is executed multiple times before an event occurs and it's not the Application_Init() event which I haven't been able to reproduce and I'm beginning to doubt that it exists.

    I can't use the just-in-time debugger because it starts saying that I have to run it as administrator, which I do, then I get many error messages saying that it could not load modules and finally what I press does nothing. I have read that this debugger is only to be used from executables, not from VS.

    You talk about working locally but I have tried to activate iis express and that option does not appear in VS 2022. In the examples that I have found on the internet, images of VS 2019 appear with options that I do not have.

    As I said, sometimes you can stop the execution at Application_Start() but normally it only stops at Session_Start().

    On Sql server I have found many serious flaws in T-SQL, which I have demonstrated, for Spanish and Catalan languages and Microsoft has finally recognized it in writing and for years they have told me that "they are going to work on it (lie)".

    After 2 weeks I have found a serious bug in Asp.net that I explain at: https://learn.microsoft.com/en-us/answers/questions/1284793/all-events-are-executed-2-times

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.