Thursday, November 27, 2008

Compatibility with IE-8

Hi,

This is regarding the “compatibility with IE-8”. We have two different ways to configure IE 8 to emulate/render the web site like IE 7 without any GUI & JavaScript issues.


First one using IE 8 browsers provides way to open web site exactly similar to IE 7:

To confirm that browsing in Internet Explorer 8 Standards mode is the cause of an issue, follow these steps:

  1. Open Internet Explorer 8 Beta 1.

    Note If you do not have Internet Explorer 8 Beta 1 installed, you can download it from the following Microsoft Web site:

http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx (http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx)

  1. Click Emulate IE 7 on the menu bar, and then close the Internet Explorer browser window.
  2. Open Internet Explorer 8 Beta 1, verify that the Emulate IE 7 button is depressed, and then visit the affected Web site.
  3. Make sure that the affected Web site is now displayed correctly.
  4. Click Emulate IE 7 to disable Internet Explorer 7 emulation, and then close the Internet Explorer browser window.
  5. Open Internet Explorer 8 Beta 1, and then visit the affected Web site to confirm that you experience the issues again after disabling Internet Explorer 7 emulation.



Second way is to use Meta-Tag:


You can use one of the following options to force Internet Explorer 8 to render Web pages like Internet Explorer 7:


· Per-site basis



Site owners and administrators can include the following custom HTTP header to force Internet Explorer 8 to render Web pages like Internet Explorer 7:


X-UA-Compatible: IE=EmulateIE7



To add a custom HTTP response header at the Web site level in Internet Information Services 7 on a Windows Server 2008-based computer, follow these steps:

    1. Click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.
    2. Under Connections, double-click the server that you want, and then double-click Sites.
    3. Click the Web site where you want to add the custom HTTP response header.
    4. Under Web site name Home, double-click HTTP Response Headers in the IIS section.

      Note In this step, Web site name is the name of the Web site.
    5. Under Actions, click Add.
    6. In the Name box, type X-UA-Compatible.
    7. In the Value box, type IE=EmulateIE7.
    8. Click OK.

To add a custom HTTP response header at the Web site level in Internet Information Services 6 and earlier versions, follow these steps:

    1. Click Start, click Run, type inetmgr.exe, and then click OK.
    2. Expand the server that you want, and then expand Web Sites.
    3. Right-click the Web site that you want, and then click Properties.
    4. Under Custom HTTP headers, click Add.
    5. In the Custom header name box, type X-UA-Compatible.
    6. In the Custom header value box, type IE=EmulateIE7.
    7. Click OK two times.


· Per-page basis



Site owners and administrators can include the following special HTML tag after the tag on the page:



The following example shows use of this Internet Explorer 7 compatibility mode tag on a per-page basis:

  
  
  My Web Page
  

Content goes here.




· Testing your site with the meta-tag



To verify you have installed the tag correctly on your site, follow these steps:

    1. If you do not have Internet Explorer 8 Beta 1 installed, you can download it from the following Microsoft Web site:

http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx (http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx)

    1. Download the Internet Explorer 8 Beta 1 security update that is described in Microsoft Knowledge Base article 951804. This update adds support for the IE=EmulateIE7 tag. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

951804 (http://support.microsoft.com/kb/951804/ ) MS08-031: Security update for Internet Explorer 8 Beta 1


For more information about the EmulateIE7 tag, visit the IEBlog Web site:

http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx (http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx)

    1. Browse your site in Internet Explorer 8 Standards mode and verify you do not encounter issues described in the "Symptoms" section.


Thanks,

Paresh B

Wednesday, November 19, 2008

Image Editor



Hi All,


Lots of time we used to develop image resizing code (creating thumbnail or resizing image to required height & width), but keeps on forgetting the code, even happen with me too. This code is not actually written by me, but posted here for future references.


This code is posted to keep the code for resizing & sacing an image uploaded.


Resize Image:


Below method shows the code to resize an uploaded image.


Parameters:

  1. (Bitmap imgToResize)[ System.Drawing.Image] – This is an actual image uploaded or provided for resizing.
  2. (Size size) – This is the size of the new resized image.


Code:

  1. The next step is to actually figure out what the size of the resized image should be. The first step is to calculate the percentages of the new size compared to the original. Next we need to decide which percentage is smaller because this is the percent of the original image we will use for both height and width. And now we calculate the number of height and width pixels for the destination image.
  2. The final thing to do is create the bitmap (System.Drawing.Bitmap) which we will draw the resized image on using a Graphics (System.Drawing.Graphics) object. I also set the interpolation mode, which is the algorithm used to resize the image. I prefer HighQualityBicubic, which from my testing seems to return the highest quality results. And just to clean up a little I dispose the Graphics object.


public static Bitmap ResizeImage(Bitmap imgToResize, Size size)

{

int sourceWidth = imgToResize.Width;

int sourceHeight = imgToResize.Height;

float nPercent = 0;

float nPercentW = 0;

float nPercentH = 0;


nPercentW = ((float)size.Width / (float)sourceWidth);

nPercentH = ((float)size.Height / (float)sourceHeight);


if (nPercentH <>

nPercent = nPercentH;

else

nPercent = nPercentW;


int destWidth = (int)(sourceWidth * nPercent);

int destHeight = (int)(sourceHeight * nPercent);


Bitmap b = new Bitmap(destWidth, destHeight);

Graphics g = Graphics.FromImage((Image)b);


g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);

g.Dispose();

return (Bitmap)b;

}


Save Image Code:


Below method will save the resized image to the given path.

  1. (string path) – Mapped path for saving image with Image Name.
  2. (Bitmap img) [System.Drawing.Image] – This is an actual image.
  3. (long quality) – This parameter used like number of pixels.


public static void SaveJpeg(string path, Bitmap img, long quality)

{

// Encoder parameter for image quality

EncoderParameter qualityParam =

new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);

// Jpeg image codec

ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");


if (jpegCodec == null)

return;


EncoderParameters encoderParams = new EncoderParameters(1);

encoderParams.Param[0] = qualityParam;

img.Save(path, jpegCodec, encoderParams);

}



private static ImageCodecInfo getEncoderInfo(string mimeType)

{

// Get image codecs for all image formats

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

// Find the correct image codec


for (int i = 0; i <> if (codecs[i].MimeType == mimeType)

return codecs[i];

return null;

}



Thanks,

Paresh Bhole

Tuesday, October 21, 2008

Session, ViewState, Cache, Application


Session

View State

Cache

Application

Modes

In-Proc,

State Server,

SQL Server

-

Page Output Cache,

Fragment Cache,

Data Cache,

Data Source Cache

-

Dependency

Cookie – if not a cookie less to store Session ID.

e.g. ASP.NET_SessionId cookie gets created.

Cookie less – URL append with Session Id.

SQL Cache Dependencies,

File,

Query String Key

Storage Location

Data is stored in memory (in process),

Web Server.

Page (but can be modified to overwrite the storage mechanism to
store viewstate else where, esp. Session, Application, File or DataBase)

Data is stored in memory (in process),

Web Server

Data is stored in memory (in process),

Web Server

Can Store

Complex Objects & Any Data

e.g. DataSet

Any serializable class to View State.

e.g. Strings, DateTimes, and Integers

Page Output, Complex Object (e.g. DataSet),

Note

Anything that you add to View State must be added to the hidden __VIEWSTATE form field. If this field gets too big, it can have a significant impact on your page's performance.

View State is loaded after the Page InitComplete event, and View State is saved after the Page PreRenderComplete event. This means that you should not attempt to retrieve a value from View State before or during the InitComplete event. You also should not attempt to add a value to View State after the PreRenderComplete event.

Application state is little used in ASP.NET applications. In most cases, you should use the Cache object instead of Application state because the Cache object is designed to manage memory automatically.

Thanks,

Paresh Bhole

Thursday, October 2, 2008

Session Mode - State Server



In previous post we see what Session is, how to use it and what are all Modes of storing Session’s.


Now, we will see How to use State Server to store ASP.Net Session.


When you enable State Server Session state, Session state information is stored in a separate Windows NT Service. The Windows NT Service can be located on the same server as your web server, or it can be located on another server in your network.


If you store Session state in the memory of a separate Windows NT Service, then Session state information survives even when your ASP.NET application doesn't. For example, if your ASP.NET application crashes, then your Session state information is not lost because it is stored in a separate process.


Furthermore, you can create a web farm when you store state information by using a Windows NT Service. You can designate one server in your network as your state server. All the web servers in your web farm can use the central state server to store Session state.


You must complete the following two steps to use State Server Session state:

  • Start the ASP.NET State Service.
  • Configure your application to use the ASP.NET State Service.



You can start the ASP.NET State Service by opening the Services applet located at Start, Control Panel, Administrative Tools (see below image). After you open the Services applet, double-click the ASP.NET State Service and click Start to run the service. You also should change the Startup type of the service to the value Automatic so that the service starts automatically every time that you reboot your machine.















If you want to run the ASP.NET State Service on a separate server on your network, then you must edit a Registry setting on the server that hosts the ASP.NET State Service. By default, the ASP.NET State Service does not accept remote connections. To allow remote connections, execute RegEdit from a command prompt and set the following Registry key to the value 1:



HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection


After you start the ASP.NET State Service, you need to configure your ASP.NET application to use it. The web configuration file in shown below enables State Server Session State.



version="1.0"?>

<configuration>

<system.web>

mode="StateServer"

stateConnectionString="tcpip=localhost:42424"

stateNetworkTimeout="10" />

<machineKey

decryption="AES"

validation="SHA1"

decryptionKey="306C1FA852AB3B0115150DD8BA30821CDFD125538A0C606DACA53DBB3C3E0AD2"

validationKey="61A8E04A146AFFAB81B6AD19654F99EA7370807F18F5002725DAB98B8EFD19C7113

37E26948E26D1D174B159973EA0BE8CC9CAA6AAF513BF84E44B2247792265" />

system.web>


The web configuration file modifies three attributes of the sessionState element. First, the mode attribute is set to the value StateServer. Next, the stateConnectionString attribute is used to specify the location of the ASP.NET State Server. In above file, a connection is created to the local server on port 42424. Finally, the stateNetworkTimeout attribute is used to specify a connection timeout in seconds.



Note: You can configure the ASP.NET State Server to use a different port by modifying the following Registry value:


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\Port


You need to stop and restart the ASP.NET State Service with the Services applet after making this modification.


Notice that the web configuration above includes a machineKey element. If you are setting up a web farm, and you need to use the same State Server to store Session state for multiple servers, then you are required to specify explicit encryption and validation keys. On the other hand, you don't need to include a machineKey element when the ASP.NET State Server is hosted on the same machine as your ASP.NET application.



Warning: Don't use the web configuration without modifying the values of both the decryptionKey and validationKey attributes. Those values must be secret.


After you complete these configuration steps, Session state information is stored in the ASP.NET State Server automatically. You don't need to modify any of your application code when you switch to out-of-process Session state.


Thanks,

Paresh Bhole


Hello

Thanks for checking out my post...

... Paresh Bhole