I have asp.net application. I am forcibly end this application and on the time of that i want to update my view page count value in database. If anyone known plz help me.
I also written code in global.asax file
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shut`enter code here`down
}
but this is not working when i forcibly end application.
I don't think that this is a very idea to try to save the data upon exiting if it's important to you.
If you still want to try and you use .NET Framework 4.5.1, you can listen to the HostingEnvironment.StopListening event, which fires when an application shut down is pending:
void Application_Start(object sender, EventArgs e)
{
HostingEnvironment.StopListening += (o, args) => SaveTheDataHere();
}
This will save the data if the hosting environment is shut down in an orderly manner, not if it abruptly crashes.
Needless to say, this won't fire if there is a fire in the server room, a BSOD halts the OS, someone trips over a power cable, etc.
A better approach would be to offload the visit event (count) immediately or periodically (depending on what level of potential data loss i acceptable) to some error resilient external process, such as a message queue.
I got my answer,
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shut`enter code here`down
}
this event works only when the following things happens then fire.
Update web.config.
Update dll file in BIN.
Stop OR restart IIS.
Application pool recycle.
So i implemented a web service for this to update my records in database periodically.
Related
I am using visual studio professional 2015, c# .net framework 4.
I have created a service for windows that sends and receives data on the serial port. It is intended to start when the computer starts and shutdown when the computer is shutdown. It should not hang or stop otherwise.
I have been running tests and find that when windows does an update it causes my service to hang. I have no idea how to debug this hang.
I would appreciate any ideas on how to start tracking down this bug.
thanks.
Here's something that might help.
When I write a service, I typically add an event handler to this AppDomain event called UnhandledException.
It's sort of a catch-all exception handler and has come in handy on a number of occassions and helps you improve your error handling, in general.
// Add this code to the Service Start method or the constructor
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
// Then add this method to your service class, it will be invoked when
// your code encounters an exception that is not trapped by a try/catch/finally
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
Trace.TraceError("Unhandled Exception occurred in service: {0}", ex);
}
Feel free to replace the Trace logging with your own logging framework if necessary.
Hope this helps.
I'm using fiddlercore in one of my application, but problem is that when I exit application and use this code to exit application
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Fiddler.FiddlerApplication.Shutdown();
}
I'm unable to connect to internet. Here is the screenshot of my registry after exiting application.(And i'm using fiddlercore proxy while submitting this question as i'm not able to use my internet without fiddlercore)
FiddlerApplication.Shutdown() must be used with care especially you have to ensure no traffic is being send at shutdown time.
To reliably get the proxy settings back to default, de-attach proxy instead like
FiddlerApplication.oProxy.Detach();
I have developed a Silverlight application locally on my laptop.
Everything works fine however when I deploy it to the server the web service runs fine, in that it talks to the data base and gets the desired results. My problem lies with the front-end SL app where it is bringing up this error:
Debugging resource strings are unavailable
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at FrontEnd.WebService.UIDReturnCompletedEventArgs.get_Result()
at FrontEnd.Views.Users.client_UIDReturnCompleted(Object sender, UIDReturnCompletedEventArgs e)
at FrontEnd.WebService.Service1SoapClient.OnUIDReturnCompleted(Object state)
Caused by: [Async_ExceptionOccurred]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.1.10329.0&File=System.dll&Key=Async_ExceptionOccurred
So I went to the link given and it stated that is was a Async_ExceptionOccurred error.
Is this a timing issue? The UIDReturnis a web method that brings back a user ID from the database, this is initiated on page load of the Silverlight page, I thought perhaps the value was not back in time and therefore this is why it was crashing however this works locally and on the test server so perhaps it is an IIS issue?
Here is where the web service is called-
void OnLoadCompleted(object sender, RoutedEventArgs e)
{
string fullUserName = WebContext.Current.User.DisplayName;
string userName = fullUserName.Substring(fullUserName.IndexOf('\\') + 1);
WebService.Service1SoapClient client = new WebService.Service1SoapClient();
client.UIDReturnCompleted += new EventHandler<UIDReturnCompletedEventArgs>(client_UIDReturnCompleted);
client.UIDReturnAsync(userName);
}
The fullUserName is from the current logged in user, perhaps this value has not been loaded yet and due to this it is breaking the connection.
This seems to be related to this post to which I have previously answered: Consume WCF library in Silverlight 4 application
i' m developing webapp in ASP.NET 2.0 (C#). I've problem to resolve issue.
The application should show users on-line, and only for administrator should show the user name. I'm using Application[] object to store usermame and count, setting the value in Globall.asax file.
In the following code i'll show the section relative to counter:
protected void Application_Start(object sender, EventArgs e){
Application["OnlineCounter"] = 0;
}
protected void Session_Start(Object sender, EventArgs e){
// Code that runs when a new session is started
if (Application["OnlineCounter"] != null){
Application.Lock();
Application["OnlineCounter"] = ((int)Application["OnlineCounter"]) + 1;
Application.UnLock();
}
}
protected void Session_End(Object sender, EventArgs e){
// Code that runs when a new session is started
if (Application["OnlineCounter"] != null){
Application.Lock();
Application["OnlineCounter"] = ((int)Application["OnlineCounter"]) - 1;
Application.UnLock();
}
}
Using this code on my local machine i can count correctly the online user.
Instead, when i publish this code on server (Windows 2003 Server and IIS6) i found the following problem:
accessing from my machine with 3 different user (using different browser), i will see only 1 user in a single page (In each browser i see only 1 online user) !
There are some issue for this ? Any suggestion is appreciated.
Thanx
You can use a performance counter to get that number.
Here you have the list of performance counters for ASP.NET. Look for the description of "Sessions Active" under "ASP.NET Application Performance Counters".
Then you can use PerformanceCounter class to get the value of that performance counter for you application.
The problem is that this requires privileges:
To read performance counters in Windows Vista, Windows XP Professional x64 Edition, or Windows Server 2003, you must either be a member of the Performance Monitor Users group or have administrative privileges.
One way to do this would be to impersonate a part of your application to be run by a user with those privileges. It could be an .asmx web service, or the web forms itself which will show the required info. You can impersonate only that service using location and identity impersonate in web.config. Set up a user with the needed privileges and impersonate that user.
Is the server configured to use multiple worker processes per application pool?
ASP.NET State Management Recommendations: http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx
Application scope: The scope of application state can also be a
disadvantage. Variables stored in application state are global only to
the particular process the application is running in, and each
application process can have different values. Therefore, you cannot
rely on application state to store unique values or update global
counters in Web-garden and Web-farm server configurations.
Configuring Web Gardens with IIS 6.0: https://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/659f2e2c-a58b-4770-833b-df96cabe569e.mspx?mfr=true
I have a Silverlight-Application which is hosted in a ASP.NET-Site. Now, I need to execute something at the first start of the application (run code for update database). I am searching the right place to do this.
Can anybody help me where I have to put this code? - Thanks.
You can add to the Startup event in your Application class, e.g.
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
... startup code here
}
}
See MSDN. Note that this runs on the client side - not the server side. Code in your silverlight application does not run on the server.
If your code has to run on the server, host your silverlight control in an aspx page and override the page's Page_Load event to execute code BEFORFE the silverlight client is sent to the browser.