I am using IIS7.5 to force my web app to load automatically (startMode="AlwaysRunning"), and I now want to preload my cache data. I am a bit confused though because two approaches seem identical:
use Application_Start in global.asax
use serviceAutoStartProviders in IIS config files
They seem rather redundant and doing the same thing. If they are, I guess I would rather use Application_Start than create code dependencies in IIS configuration files. Any advice?
The Application_Start in the global.asax is fired when the application receives it's first request (first user or autostart) so it is not used to start the site.
Use serviceAutoStartProviders to start
http://www.asp.net/whitepapers/aspnet4#0.2__Toc253429241
The IIS Application Warm-Up Module is easier to use
http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization
Related
We have a legacy webforms app and a new section of our site developed with MVC. It works a treat as an application in the Default Web Site in IIS.
Only downside is that the root site's session object isn't passed to the application. We have a work around for this.
A consultant is convinced that we don't need to set it up as an application and it can all be done via handlers and route mappings. He conveniently has not provided us with any details though and I have been tasked to implement it.
The best I have achieved was to add a Module Mapping to the Handler Mapping section in IIS. This filters coolmvcapp/* with Module isapimodule to a virtual directory who's physical path points to our new MVC app. The result is an empty page with a 200 response. Most other combinations I have tried resulted in a variety of errors. (Turns out an empty page is returned without adding the handler mapping - hey ho)
So, is this approach even possible?
I am aware that MVC and webforms can be merged together but for reasons this is something that we want to avoid.
Inside my local publish folder I have Global.asax and Global.asax.cs where Global.asax is not updated (dated one month ago) and Global.asax.cs is updated.
I check the "Build action" of the Global.asax file which is set to "Content" and Copy always in the file properties.
How to update global.asax together with global.asax.cs on publish command?
Global.asax doesn't usually change. Global.asax is compiled into a class deriving from the Global class in your Global.asax.cs.
You don't have to do anything for that. The server's compiler will pick it up itself. You just need to copy the Global.asax to your production server, where the Global.asax.cs will be compiled into an assembly.
See the MSDN:
At run time, Global.asax is parsed and compiled into a dynamically
generated .NET Framework class derived from the HttpApplication base
class. The Global.asax file itself is configured so that any direct
URL request for it is automatically rejected; external users cannot
download or view the code written within it.
So as Patrick has already mentioned, there is no need to change it. The compiler will pick it.
When you save changes to an active Global.asax file, the ASP.NET page
framework detects that the file has been changed. It completes all
current requests for the application, sends the Application_OnEnd
event to any listeners, and restarts the application domain. In
effect, this reboots the application, closing all browser sessions and
flushing all state information. When the next incoming request from a
browser arrives, the ASP.NET page framework reparses and recompiles
the Global.asax file and raises the Application_OnStart event.
i have a webapi project that uses cache library.I am using cache duration key that is used inside cache library.My question is what is the standard practice where should i put Cache duration key,from Where to pick the value of cache duration, inside appconfig of cache library or from web.config of webapi?
The web.config is the place to go in a web application. There's no such thing as app.config in an ASP.NET application. You could always build some mechanism to load configuration data from custom places but the first place a developer would look for such things is the web.config.
I want to access my windows Azure Data Cache from my Role Entry StartUp routine. However I keep getting this error:
{"ErrorCode:SubStatus:Server collection cannot be empty."}
However when I do the same from within my Controller class it loads the Data Cache fine and I can go ahead and do things with it.
Is there anything special for the Role Entry class that I have to do to access the Data Cache prior to my application starting?
Or can't I access the Cache in the Role StartUp ?
Cheers
Starting with Azure SDK 1.3, there is a major change - the Full IIS mode. Read this blog post to get full undertanding of full IIS and what is it.
In short - your RoleEntryPoint descendant (where your OnStart method is being executed) lives in whole another AppDomain (and process actually - WaIISHost.exe), while your actual web application just lives in IIS (w3wp.exe). That's why there is no way to do something in OnStart() that would affect your web applicatin or that would be able to directly read your web.config.
If you do read Azure Data Cache in OnStart to do some preload of data for the web application, just do in your Global.asax's Application_Start() event handler.
If you need to read Azure Data Cache in OnStart for reason's specific to the RoleEntryPoint, you have to load the configuration from web.config. Web.config is placed in "./bin/web.config" relative to your AppRoot folder. (there are two copies of your application when you use WebRoles with full IIS - one lives in AppRoot and one lives in SitesRoot).
Hope this helps!
WebRole's OnStart probably does not use your web.config where you probably have specified server names and access keys for your AppFabric DataCache provider.
I would try manually instrumenting the server connection configuration.
I have made a web app where I am using a module which redirects without "www" urls (http://example.com/) to with "www" urls (http://www.example.com/). But as I am on shared hosting server, where I don't have permission to implement a HttpModule, then I tried the same module code with Global.asax file. That works!
I used the following (Application_BeginRequest()) event to implement my HttpModule functionality.
void Application_BeginRequest()
{
//module code
}
The module and application is working well and correctly from Global.asax file But I am worried about the performance.
Why we use the HTTPModules in asp.net If we can implement the same using Global.asax file. Is there ay performance differences between both. Or any difference about which I need to worry about when using Global.asax file instead of HttpModule ??
Please explain!
Global.asax inherits from HTTPApplication, and HTTPModules must implement the IHTTPInterface.
The HTTPModules Init method gets the HTTPApplication object passed in.
In the Init method you can hook into the events of HTTPApplication.
I would recommend to use HTTPModules wherever you can.
Especially if you make shrink-wrapped software where the customer can replace your global.asax with their own.
There is pretty much no difference. The point of HTTPModules is for clarity and seperation. Often people will pipe the request through several HTTPModules, which is something you can't get with global.asax.