asp.net Run code when session is available but page has not been loaded? - asp.net

Is there any way to run code when session is available but page has not been loaded?
The closest thing i have found is Global.asax AcquireRequestState.
But it seems to run right after the constructor for the page.

Related

Ajax not working on Server

I have downloaded the latest toolkit from https://www.nuget.org/packages/AjaxControlToolkit/.
Problem is it works fine on my local host but not when i upload it to the server. I don't even get an error message. Simply anything Ajax related is not working. I'm suspecting that the installation I did is the problem, since it does everything automatically for me and in my project I can't add a ScriptManager since it keeps saying that I already have one in my system, eventhough I can't see in anywhere in my code.
Do anyone have any idea what the problem might be or what I'm missing?
You have a ScriptManager on the master page, and therefore when your child page gets composited with the master page there ends up being two script managers.
The normal solution is to only have the ScriptManager on the master page.

force reload of aspx page from silverlight xaml

I've a Silverlight application that is called from a asp .net project. I have a link in the silverlight project that brings the user back to the asp.net project. I do not want this to happen in a new window.
At the moment, it returns me to the cached page. I want to force a reload of it.
Currently onclick event of the link invokes the following code:
HtmlPage.Window.Navigate(new Uri("http://ipaddress/menu.aspx"));
Any suggestions on how I could enforce menu.aspx to reload when called?
I found a solution..
SOLUTION
HtmlPage.Window.Navigate(new Uri("http://ipaddress/menu.aspx?"));
This results in the page being reloaded....
Try using:
HtmlPage.Document.Submit()
It should work if your .aspx target page you wish to reload is the current page.

'System.Web.HttpContext.Current.Session' is null

I have an ASP.NET website that has been deployed since 2008 with plenty of users. From time to time, I've made updates to the site and uploaded those changes to the server without problems.
However, today, I'm trying to run the site on my development environment and I keep getting errors any time the code tries to access session state. It appears System.Web.HttpContext.Current.Session is always null!
Any suggestions on where to look? It's been a while since I worked on it and am not 100% sure if I've worked on it with the current version of ASP.NET (4.0).
Other than that, the code's been working fine and I haven't made any changes since it was last working.
More Information
I've spent all morning on this but I apparently have a larger issue.
If I step through the code, I see that my page Load handler executes. At this point, Session is not null. After that, my specialized master page executes. After that, my general master page executes. I then step through load events for a couple of controls. This all seems very normal.
Then, if I keep executing, suddenly I'm loading a specialized master page for another page and Session is now null!
If I hit F5, it the original page shows. But somehow it is causing the other page to load and without session state. If I turn off debug mode, it appears to run normally.
Obviously, I have something strange happening. I need to determine why the other page is being loaded.
Try to put a static page, something like Test.aspx and browse to that page. If it gets loaded, try to use Session property of the page in code behind. Do you still get the error? In that case, Session doesn't load. I suggest creating an HTTP Module and hooking into a method which is responsible for loading Session info. See what's wrong.
Just a guess - did you deactivate sessionState for any reason? Anything like this:
<sessionState mode="Off"/>
My apologies. The information I provided was completely misguided and was not sufficient to resolve the issue.
The problem was actually due to some custom error handling that redirected to an error page. This was configured in web.config. This error page was using the master page that my code was mysteriously executing.
Apparently, an error was occurring within the GridView control. This is ASP.NET code and not my own, so I was unable to step through it or catch it with a regular handler.
This was hard to understand. If I was executing the Load event handler of my error page, then it would've been obvious. But it appears to have skipped over that. Thus, my confusion.
Try checking the global.asax file or any other pre-load events and make sure the Session is not set to NULL explicitly.
Maybe your erring master page is calling code from some external class where the session object is not available?

If my ASP.NET webapp isn't fit for runtime?

I want to run some tests when my ASP.NET webapp comes online (preferably before anyone tries to access it), to make sure all of my runtime dependencies are available as I expect them to be.
When is a good time to perform these tests (e.g. Application_Start, Application_Init, somewhere else, etc), and what's a good technique for making my webapp unavailable to users if my tests fail (it shares an app pool with other apps I don't want to affect)?
One approach would be to put your checks in the Application_Start event, and update a static property (or properties) in the Global class with the result of your test.
If you're using master pages, each master page (I've personally never seen more than 2 base master classes in a project) could check the static property in the Global class, and redirect to an "app offline" page if appropriate. Since the static property would only be updated when the application started, there shouldn't be any performance impact.
The code in your master page's OnLoad event might look like this...
if (!Global.WasDependencyCheckSuccessful)
{
//redirect to error page
}
If you're not using master pages, this may not be the best solution (because you would need to update each web form in your site individually).
You can put it in the Application_Start event in the global.asax.
To bring your app offline, simply create an App_Offline.htm file. I do it on our server by having an "App_Offline.html" file and when I need to bring it offline, I have the code rename it to change the extension from .html to .htm, and reverse that to bring it back online.
Of course, to bring it back online, you have to do it from code outside of your website, or do it manually, because if the file is there, the code in your website won't run...

Calling web service asynchronously still hangs application

I have an aspx page with three input buttons.
The first button, using javascript/ajax, fires off a call to an IHttpAsyncHandler.
The Handler calls a web service on another server (which generates a report and returns the path to the report file). In the ajax callback, XmlHttp.responseText returns the proper path and a window.open(path) call opens the report, no problem.
The other two buttons open new windows to other aspx pages on the current site.
The problem is, after I click the first button, clicking the other two buttons do not give me the aspx pages until after the report is displayed. Blank windows do pop up, but nothing is rendered until the report is done.
What causes that hang time? I thought calling the report using ajax and an Async handler would not interfere with popping up other aspx pages.
Other attempts:
1. creating a reportGenCompletedEventHandler in the main aspx and calling the service using reportGenAsync(...)
2. calling (in the main aspx)
AddOnPreRenderCompleteAsync(New BeginEventHandler(...),New EndEventHandler(...)
3. calling (in the main aspx)
Page.RegisterAsyncTask(New PageAsyncTask(...))
Page.ExecuteRegisteredAsyncTasks()
4. same as above, creating a separate AsyncHandler, but also creating a separate thread.
Obviously, I'm missing something here. Is it possible to call a web service elsewhere and still have full control of your app?
Thanks
Are the pages you're trying to hit on the same web host? If so, I'm guessing you've hit the "Max 2 concurrent connections to the same host" limit.
The link here on asp.net describes how IE8 lets you go beyond that.

Resources