Server Controller Overview
The Server Controller unit is were you can control general aspects of your Web Application, as for example, if you want to use compression, the Templates folder, how your application reacts if your user is using an unsupported browser, like IE6,among other several things.
The Server Controller is also responsible for creating user session instances, through the OnNewSession event, which is triggered when a new user connects to your web application.
In general, you do not need to add code to the server controller, except if you need custom control of a specific aspect of your application. A good reason for customizing the Server Controller is preparing your application to support Search Engines, like Goole or Yahoo. See Server Controller advanced topics for more information.
When your application is running, you have only one instance of the Server Controller class and the Server Controller will always be active, even if no user is connected to the application. You don’t need to worry about creating/destroying the Server Controller instance, as this is handled automatically by IntraWeb for you.
For a description of the Server Controller properties, method and events, please check the Server Controller class description.
How to access the Server Controller instance in your code
In some parts of your application, you may need to access the Server Controller to check and use certain property values or call some method. The easiest way to access the Server Controller is using a function available in the Server Controller unit. You need to include the unit ServerController in the uses clause of the unit you want to access the Server Controller instance, as for example, your IWForms.
- function IWServerController: TIWServerController;
- Result := TIWServerController(GServerController);
After you have added the ServerController unit to your uses clause, you simply access the Server Controller instance using the IWServerController function.
- procedure TfrmCustomers.IWLink1Click(Sender: TObject);
- xReport: TStringList;
- xNomeArquivo: string;
- xReport := UserSession.DM.ReportCustomerOrders(fCustomerID);
- xNomeArquivo := IWServerController.UserCacheDir + UserSession.DM.RandomName + ‘.txt’;
- WebApplication.SendFile(xNomeArquivo, True, ”, ‘Customer Report ‘ +
- UserSession.DM.Customers.Dataset.FieldByName(’CustNo’).AsString + ‘.txt’);
- TIWURLMap.Add(’/Customer/’, ‘index.html’, TfrmCustomers);