Sunday, April 22, 2007

Automating Excel or Word using Asp.Net 2.0

Automating Excel or Word (or any Office product) is not recommended:

Problems using Automation of Office server-side

Developers who try to use Office in a server-side solution need to be aware of five major concerns in which Office behaves differently than anticipated because of the environment. If your code is to run successfully, these concerns need to be addressed and their effects minimized as much as possible. Consider these items carefully when you build your application because no one solution can address all of them, and different designs require you to prioritize the elements differently.
1.
User Identity: Office Applications assume a user identity when they are run, even when they are started by Automation. They attempt to initialize toolbars, menus, options, printers, and some add-ins based on settings in the user registry hive for the user who launches the application. Many services run under accounts that have no user profiles (such as the SYSTEM or IWAM_[servername] accounts), and therefore Office may fail to initialize properly on startup, returning an error on CreateObject or CoCreateInstance. Even if the Office application can be started, without a user profile other functions may fail to work properly. If you plan to Automate Office from a service, you need to configure either your code or Office so that it will run with a loaded user profile.
2.
Interactivity with the Desktop: Office Applications assume that they are being run under an interactive desktop, and may in some circumstances need to be made visible for certain Automation functions to work properly. If an unexpected error occurs, or an unspecified parameter is needed to complete a function, Office is designed to prompt the user with a modal dialog box that asks the user what they want to do. A modal dialog box on a non-interactive desktop cannot be dismissed, which causes that thread to stop responding (hang) indefinitely. Although certain coding practices can help reduce the likelihood of this occurring, they cannot prevent it entirely. This fact alone makes running Office Applications from a server-side environment risky and unsupported.
3.
Reentrancy and Scalability: Server-side components need to be highly reentrant, multi-threaded COM components with minimum overhead and high throughput for multiple clients. Office Applications are in almost all respects the exact opposite. They are non-reentrant, STA-based Automation servers that are designed to provide diverse but resource-intensive functionality for a single client. They offer little scalability as a server-side solution, and have fixed limits to important elements, such as memory, which cannot be changed through configuration. More importantly, they use global resources (such as memory mapped files, global add-ins or templates, and shared Automation servers), which can limit the number of instances that can run concurrently and lead to race conditions if they are configured in a multi-client environment. Developers who plan to run more then one instance of any Office Application at the same time need to consider "pooling" or serializing access to the Office Application to avoid potential deadlocks or data corruption.
4.
Resiliency and Stability: Office 2000, Office XP, and Office 2003 use Microsoft Windows Installer (MSI) technology to make installation and self-repair easier for an end user. MSI introduces the concept of "install on first use", which allows features to be dynamically installed or configured at runtime (for the system, or more often for a particular user). In a server-side environment this both slows down performance and increases the likelihood that a dialog box may appear that asks for the user to approve the install or provide an appropriate install disk. Although it is designed to increase the resiliency of Office as an end-user product, Office's implementation of MSI capabilities is counterproductive in a server-side environment. Furthermore, the stability of Office in general cannot be assured when run server-side because it has not been designed or tested for this type of use. Using Office as a service component on a network server may reduce the stability of that machine, and as a consequence your network as a whole. If you plan to automate Office server-side, attempt to isolate the program to a dedicated computer that cannot affect critical functions, and that can be restarted as needed.
5.
Server-Side Security: Office Applications were never intended for use server-side, and therefore do not take into consideration the security problems that are faced by distributed components. Office does not authenticate incoming requests, and does not protect you from unintentionally running macros, or starting another server that might run macros, from your server-side code. Do not open files that are uploaded to the server from an anonymous Web! Based on the security settings that were last set, the server can run macros under an Administrator or System context with full privileges and compromise your network! In addition, Office uses many client-side components (such as Simple MAPI, WinInet, MSDAIPP) that can cache client authentication information in order to speed up processing. If Office is being automated server-side, one instance may service more than one client, and because authentication information has been cached for that session, it is possible that one client can use the cached credentials of another client, and thereby gain non-granted access permissions by impersonating other users.


(courtesy: http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757)

Server-side automation, Automating Excel from Asp.Net, Asp.Net Office Applications

Saturday, April 21, 2007

Increase Website Speed ASP.net

----------------------------------------------------------
' Speedup Website - Increase Website Speed ASP.net
----------------------------------------------------------

Precompiling a website will enhance the speed because pages do not have to be compiled the first time they are requested

This can also be used to create a compiled version of the site that can be deployed to a production server without source code.

To precompile use aspnet_compiler.exe from

c:\winnt\Microsoft.NET\Framework\v2.0.50727\

and from the command prompt --> aspnet_compiler -v /virtualPath
(or) aspnet_compiler -p physicalOrRelativePath -v /

you can append the above command with target path if it is for deployment.

aspnet_compiler -p "c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\PGWindow\" -v /

Redirect Page on Anonymous Entry

----------------------------------------------------------
' Checking if an user has logged in
----------------------------------------------------------

Redirect Page on Anonymous Entry

The LoginView control can be used to check if an user has logged in. The control displays one of

<asp:loginview id="LoginView1" runat="server">
<loggedintemplate>
</loggedintemplate></asp:loginview></loggedintemplate><p>Welcome back! </p>

<anonymoustemplate>
You are not logged in <a href="http://www2.blogger.com/Login.aspx">Login</a>
</anonymoustemplate></span></blockquote><span style="color: rgb(51, 102, 255);">

</span><loggedintemplate><asp:loginview id="LoginView1" runat="server">
<loggedintemplate>
</loggedintemplate></asp:loginview></loggedintemplate><p>Welcome back! </p>

<anonymoustemplate>
You are not logged in <a href="http://www2.blogger.com/Login.aspx">Login</a>
</anonymoustemplate>


The LoginView control also includes events for ViewChanging and ViewChanged, which allow you to write handlers for when the user logs in and changes status.

LoginView control, Check Login Status, Redirect Page on Login

Error ! Content controls are allowed only in content page that references a master page

----------------------------------------------------------
Content controls are allowed only in content page that references a master page.
----------------------------------------------------------

This error occurs when the webpage that contains a content element,
does not have any master page.

For example,
<%@ Page Language="VB" MaintainScrollPositionOnPostback="true" %>



will raise an error.

Either remove the Content controls or include appropriate master page

Solution:
<%@ Page Language="VB" MasterPageFile="~/MyMast.master" MaintainScrollPositionOnPostback="true" %>

Prevent Webpage scroll back to the top position

----------------------------------------------------------
Prevent Webpage scroll back to the top position
----------------------------------------------------------

If the webpage position is returned to the top after every post back
it will be an irritant.

When the MaintainScrollPositionOnPostback property is set to true, the user is instead returned to the last position on the page.

<%@ Page Language="VB" MaintainScrollPositionOnPostback="true" %>

This property is by default false

When Web pages are posted back to the server, the user is returned to the top of the page. On long Web pages, this means that the user has to scroll the page back to the last position on the page.








Submit URL