Web Garden on IIS 7

Saturday, 13 June 2009 16:53 by emanuele
Each Application Pool runs with a single worker process (w3wp.exe).
From IIS 6, we can assign multiple worker process on a single application pool. This method is called Web Garden.
Many worker process can provide better performance and response time to your application.
There are some restriction to use web garden for your application. You must use "out proc" for Session Mode and "Session State Server" or "Sql-server session state".
If you use "in proc" for Session Mode your application not work correctly.

To create a web garden, right click on the Application Pool -> Advance Setting and set the value of Maximum Worker Process under the Process Model section.

Tags:   ,
Categories:   Asp.net | IIS
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to maintain scrollposition after post back?

Tuesday, 9 June 2009 06:31 by emanuele

By default When web pages fire a post back to the server, the browser scroll is returned to the top of the page.
When the page is tall, it is very annoying.
You are three ways to kill this behaviour.

   1. Application level: To set the property by default for all pages in the website, open web.config and add the attribute to the pages node.

      <pages maintainScrollPositionOnPostBack="true">

   2. Page Level: for a particular page, open the aspx and set the property

      <%@ Page MaintainScrollPositionOnPostback="true" >

   3. Code level: to set the property programmatically

      Page.MaintainScrollPositionOnPostBack = true;

 

Categories:   Asp.net | C#
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Hello, I'm Bing.

Wednesday, 3 June 2009 14:17 by emanuele

The new generation of search is called Bing.
If you go @Bing.com and try to search anything you will be amazed.
The thing that makes bing different from the other search engines is the intelligent search tool.
Research indicates that 66% of people search over internet before to deicide something.
The search results depend on what you searched.
If you search "South Park" in videos, the result page rendered to have a great user experience for videos. If you go hover the image preview with mouse let see a video preview with sound. In the left you can filter the results list by length, resolution, screen size and source.
If you search "Milan to Dublin" in travel, Bing provides a search result with many offers to travel. You can specify and filter the days, the company and search hotels and monuments in the city. This is all on the same page.
The best choice to explain how it works, it's try this @Bing.com

 

 

Tags:  
Categories:   Bing
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to backup and restore a Sharepoint site

Monday, 25 May 2009 07:47 by emanuele

- Back up a sharepoint site (for the filename you can use .bak)

Stsadm –o backup –url <SiteURL> -filename <FileName>

- Restore a sharepoint site from backup

Stsadm –o restore –url <restoretoURL> -filename <filetorestorefrom>

The location for stsadm is C:\Program Files\common files\microsoft shared\web server extensions\12\bin

Start, Stop and Pause Sql Server Services from Command Line

Wednesday, 29 April 2009 11:59 by emanuele

You can start, stop, pause and resume Sql Server Services as all other services.

To manage the default database istance open command prompt and type:

  •  NET START MSSQLSERVER  - Starts SQL Server
  •  NET STOP MSSQLSERVER  - Stops SQL Server
  •  NET PAUSE MSSQLSERVER  - Pauses SQL Server
  •  NET CONTINUE MSSQLSERVER  - Resumes SQL Server


 
 
Tags:  
Categories:   Sql Server
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to enable http compression on IIS 6.0

Friday, 20 March 2009 08:33 by emanuele

With this simple eight steps, you can enable the http compression on IIS 6.
It is useful if your application has very hard pages, but the compression requires much cpu usage.

1. Open a command prompt, type net stop iisadmin and press ENTER.

2. Type cd c:\inetpub\adminscripts and press ENTER.

3. Type CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx" and press ENTER.

4. Type CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx" and press ENTER.

5. Type CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel "9" and press ENTER.

6. Type CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel "9" and press ENTER.

7. Type cscript.exe adsutil.vbs set W3SVC/ID/Root/WebServiceTG/DoDynamicCompression True and press ENTER. (ID is the identifier of the application that you can find on the coloumn Identifier of IIS Manager)

8. Type net start w3svc and press ENTER.

Tags:   ,
Categories:   Asp.net | IIS
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to measure elapsed time in C# with StopWatch

Friday, 20 March 2009 04:50 by emanuele

StopWatch class can measure elapsed time for one interval.
We can use for measuring performance of the new code blocks or algorithms. Use IsRunning method to determine the state of StopWatch object.
Use Start method to begin measuring elapsed time, and Stop method to stop measuring elapsed time.

{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
textBox1.Text = DateTime.Now.TimeOfDay.ToString();
Application.DoEvents();

// Perform a long process
Thread.Sleep(34564);

stopwatch.Stop();
textBox2.Text = DateTime.Now.TimeOfDay.ToString();
textBox3.Text = stopwatch.Elapsed.Milliseconds.ToString();
Application.DoEvents();
}

Tags:   ,
Categories:   Asp.net | C#
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to configure the pattern layout of Log4net

Friday, 20 March 2009 04:48 by emanuele

With Log4net, you can configure the layout of the string that you want to log.
It's very simple, because you can change the pattern layout string in few seconds and without compiling the application.
You don't compile everytime change the pattern layout string, because it is in the application config.
For web application it is in the web.config file and for desktop application it is in the app.config.
Each pattern member starts with % and is followeb by the name of pattern member.
You can change the width, padding, left and right justification for each pattern member.

Sometimes, I use this layout pattern: %type %file %line %method %location %class %C %F %L %l %M %n , but below I explain every single member in order to you can create your pattern layout.

a or appdomain Friendly name of appdomain
c or logger Used to output the logger of the logging event
C or class or type The fully type name of the caller class
d or date The date of logging event in the local time zone
exception The exception
F or file The file name where the logging request was issued
identity or u The active user
l or location Location information of the caller
L or line The line number from where the logging request was issued
level or p The level of the logging event
m or message Application supplied message associated with the logging event
M or method The method name where the logging request was issued
n or newline Line separator
r or timestamp The timestamp when the logging request was issued
t or thread The name of thread that generated the logging event
username or w The Windows Identity for active user
Tags:   , ,
Categories:   Asp.net | Log | C#
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Encrypt the ViewState

Friday, 20 March 2009 04:45 by emanuele

By default, the ViewState encryption is disabled in the web applications.
So it is recommended not send private data through Viewstate at least that you are not using SSL.
There are two ways to encrypt your ViewState:
1. Encrypt ViewState in every Page
2. Encrypt ViewState in web.config for all pages in your applications In the first case, add the attribute in the directive <%@Page ViewStateEncryptionMode="Always" %> in your single page.
In the second case, add the attribute viewSateEncryptionMode="Always" in your web.config.
Then add the algorithm of decryption in your web.config.
There are much key of decryption, but the key AES is the best for performance and for security.

See the example:

<configuration>
<system.web>
<machineKey decryptionKey="AutoGenerate,IsolateApps" decryption="AES" />
</system.web>
</configuration>

For more informations go to http://msdn2.microsoft.com/en-us/library/ms998288.aspx

Tags:  
Categories:   Asp.net | C#
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Download xml file from webservices

Friday, 20 March 2009 04:39 by emanuele

Sometimes, some network configurations don't allow to access directly to web services.
One way is download the xml file that xml web services returns and load that in a dataset.
I wrote a small function to download xml file from web services.
It's simple, but it's a good starting point to develop other things.

 

public bool DownloadXmlFromService()
{
string result = "";
try
{
WebProxy proxy = new WebProxy(" proxy address ", port number );
proxy.Credentials = new NetworkCredential( user id , password, domain );
WebRequest request = WebRequest.Create("http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=Italy");
request.Proxy = proxy;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
System.Text.Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader reader = new System.IO.StreamReader(stream, ec);
char [] chars = new Char[256];
int count = reader.Read(chars, 0, 256);
while(count > 0)
{
string str = new String(chars, 0, 256);
result = result + str;
count = reader.Read(chars, 0, 256);
}
response.Close();
stream.Close();
reader.Close();

result = result.Replace("&lt;","<");
result = result.Replace("&gt;",">");

if (File.Exists("temp.xml"))
{
File.Delete("temp.xml");
}

System.IO.StreamWriter ToFile = new StreamWriter("temp.xml");
ToFile.Write(result);
ToFile.Close();
}
catch(Exception exp)
{
string str = exp.Message;
return false;
}

return true;
}

Tags:   ,
Categories:   Asp.net | C# | WebServices
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

String Format Online Utility

Friday, 20 March 2009 04:33 by emanuele
Until I surf over internet, I've found an incredible tool for C# and Vb.Net developer.
If you don't remember (like me) all possible formatting options, you found this utility very usefull.
It's a Silverlight project, indeed you must install the silverlight plugin on your browser (if you haven't).
Follow the instructions on the utility and copy the sample code with your pretty Ctrl + C.

http://blog.toolico.com/2008/tool/string-format-made-simpl

Tags:  
Categories:   Online Tool
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Log4net: use Sql Server to log your application events

Thursday, 19 March 2009 06:42 by emanuele
In the previous article on the Log4net configuration, I explain how to configure Log4net with the file appender.
In this article I explain how to configure Log4net with the Sql Server appender.
It is very similar, but we see in detail the new configuration.

Download

You can download the latest version of Log4net from this location.

Add reference to your solution

In Visual Studio 2005 select Project -> Add Reference.
In the tab Browse, find and select the dll Log4net.dll in your local folder.

Modify web.config

Into web.config file add this code into the section Configuration->Configsections:

<configSections>
    <section name="log4net"
      type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
</configSections>
<log4net>
  <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
    <bufferSize value="100" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="server=localhost; uid=; pwd=; database=" />
    <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES
       (@log_date, @thread, @log_level, @logger, @message, @exception)" />
    <parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.RawTimeStampLayout" />
    </parameter>
    <parameter>
      <parameterName value="@thread" />
      <dbType value="String" />
      <size value="32" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%t" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@log_level" />
      <dbType value="String" />
      <size value="512" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%p" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@logger" />
      <dbType value="String" />
      <size value="512" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%c" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@message" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%m" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@exception" />
      <dbType value="String" />
      <size value="2000" />
      <layout type="log4net.Layout.ExceptionLayout" />
    </parameter>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="ADONetAppender" />
  </root>
</log4net>

Change the connectionstring parameters to connect to your database.

Create the table

In your database, create the table to use Log4net. 

CREATE TABLE [dbo].[Log](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Date] [datetime] NULL,
    [Thread] [varchar](255) NULL,
    [Level] [varchar](50) NULL,
    [Logger] [varchar](255) NULL,
    [Message] [varchar](4000) NULL,
    [Exception] [varchar](2000) NULL
) ON [PRIMARY]

Edit the Global.asax file

In the event "Application_Start" of the file Global.asax add this line:

log4net.Config.XmlConfigurator.Configure();

Begin to log

In every page you want to log something, add the static variable like below:
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

This class has 5 levels of severity to log the operations:

log.Debug("log something at this level")
log.Info("log something at this level")
log.Warn("log something at this level");
log.Error("log something at this level");
log.Fatal("log something at this level");

You find the official documentation at this link.

If you want to log on the file system, read the previous article on Log4net.

Tags:   , ,
Categories:   Asp.net | Log
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Log4net: simple way to use in your Asp.net application

Thursday, 19 March 2009 06:22 by emanuele

Introduction

Log the actions of your applications is very important especially when you develop new features or develop very difficult logical business.
But it is also important when users use your applications to understand the critical issues or problems.
To implement quickly the log operations Apache developed an opensource library for .Net developers.

Download

You can download the latest version of Log4net from this location.

Add reference to your solution

In Visual Studio 2005/2008 select Project -> Add Reference.
In the tab Browse, find and select the dll Log4net.dll in your local folder.

Modify web.config

Into web.config file add this code into the section Configuration->Configsections:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

Yet, add the section:

<log4net>

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

<file value="c:\temp\web.log" />

<appendToFile value="true" />

<maximumFileSize value="1024KB" />

<maxSizeRollBackups value="10" />

<layout type="log4net.Layout.PatternLayout">

<conversionPattern value="%date %level %logger - %message%newline" />

</layout>

</appender>

<root>

<level value="DEBUG" />

<appender-ref ref="RollingFile" />

</root>

</log4net>

 In this configuration will create a log file into the folder "c:\temp\" until its size is 1024Kb.
After this size the name of file will be web.log.1 until 10.
At this link you can find another configurations.

Global.asax

In the event "Application_Start" of the file Global.asax add this line:

log4net.Config.XmlConfigurator.Configure();

Begin to log

In every page you want to log something, add the static variable like below:

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

This class has 5 levels of severity to log the operations:

log.Debug("log something at this level")
log.Info("log something at this level")
log.Warn("log something at this level");
log.Error("log something at this level");
log.Fatal("log something at this level");

Simple and fast to use.

You find the official documentation at this link.

Tags:   , ,
Categories:   Asp.net | Log
Actions:   E-mail | Kick it! | Permalink | Comments (0) | Comment RSSRSS comment feed