Welcome to MSDN Blogs Sign in | Join | Help

IIS7 – Improving ASP.NET performance (concurrent requests) while on Integrated Mode

If you were a ASP.NET 1.1 developer, and faced some performance problems, I’m sure you would have come across the KB 821268 which talks about tweaking maxWorkerThreads, maxIoThreads in the <processModel>, minFreeThreads, minLocalRequestFreeThreads in <httpRuntime>, maxconnection in the <connectionManagement> section. But for ASP.NET 2.0, we have <processModel autoConfig=”true” /> where these settings are tweaked in the runtime.

You may experience a performance issue while running your ASP.NET applications on IIS7 integrated mode. You might want to consider tweaking the number of concurrent requests per CPU on the server which can slow down the execution of the requests, and you will see few requests just waiting to be processed. By default, it sets a limit of 12 concurrent requests, and you can tweak the number by considering the below options registry key, or a equivalent configuration change if you have .NET 3.5 SP1:

[DWORD]

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\2.0.50727\MaxConcurrentRequestsPerCPU

Set this to a value higher than 12 (12 is the default)

If you already have SP1 for .NET 3.5 installed, this can be done via configuration itself:

Change the below in aspnet.config file (found in the framework folder)

<system.web>
      <applicationPool maxConcurrentRequestsPerCPU="12" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000"/>
</system.web>

Thomas Marquart has explained about the changes in the IIS7 thread handling (integrated mode) in his blog. That’s a well written blog explaining how the ASP.NET threading model in IIS6/IIS7 handles the requests. Please read!

Posted by rakkim | 0 Comments
Filed under: , ,

IIS7 – Configuring iisClientCertificateMappingAuthentication using appcmd

As you know there is no UI to configure iisClientCertificateMappingAuthentication in IIS7, it takes a little more time to configure the site for the same. Here is an article in the iis.net site which explains the steps one by one.

Configuring One-to-One Client Certificate Mappings
http://learn.iis.net/page.aspx/478/configuring-one-to-one-client-certificate-mappings/

You can also use Ulad’s VBScript to configure the mapping of the certificate, and the user credentials. I was working with one of my colleague who was trying to automate this configuration. One interesting thing to note here is these one-to-one certificate configurations MUST be present in the website level. So, if you want only your virtual directory to be using this iisClientCertificateMappingAuthentication, you need to specify the certificate-useraccount mapping configurations on the website level, and set the iisClientCertificateMappingAuthentication not enabled. And, just enable the iisClientCertificateMappingAuthentication only on the virtual directory (or application) level.

Below are the appcmd commands needed for the same (after configuring the one-to-one configuration using Ulad’s VBScript):

In this example, we will configure the IIS client certificate authentication only on the Virtual Directory level:

// disable the IIS client certificate authentication at the website level (our website is “Default Web Site”, and Vdir is “Myapplication”)

appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /enabled:false /commit:appHost

// disable anonymous authentication on the virtual directory

appcmd.exe set config "Default Web Site/Myapplication" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:false /commit:appHost

// disable windows authentication on the virtual directory

appcmd.exe set config “Default Web Site/Myapplication" -section:system.webServer/security/authentication/windowsAuthentication /enabled:false /commit:appHost

// enable iisClientCertificateMappingAuthentication, and oneToOneCertificateMappingsEnabled for the virtual directory

appcmd.exe set config "Default Web Site/Myapplication" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /enabled:true /oneToOneCertificateMappingsEnabled:true /commit:appHost

// set the SSL flags to require Client Certificates from the client connections

appcmd.exe set config "Default Web Site/Myapplication" -section:system.webServer/security/access /sslFlags:"Ssl, SslNegotiateCert, SslRequireCert"  /commit:apphost

Hope this helps!

Posted by rakkim | 0 Comments
Filed under: ,

FREB – Troubleshooting a simple error message

I just wrote a blog post on my team blog on using FREB to troubleshoot a simple error message. I’ve taken an example of a HttpModule setting the Response status to 400. This is not a common scenario, but I just want people to use FREB extensively in their troubleshooting an error message – to see which module set the status, and take it from there.

Read the post here - http://blogs.msdn.com/webtopics/archive/2009/06/12/troubleshooting-a-simple-error-message-using-freb.aspx

And, please do subscribe to my team blog RSS feed where we have bunch of folks blogging on issues which are most common to our customers, best practices, known issues, and workarounds, etc. That’s our official team blog of Microsoft IIS and ASP.NET support team.

Hope this helps!

Posted by rakkim | 0 Comments
Filed under: ,

URLScan – rejecting the request depending on the User-Agent string

I just learned this now :-) You can now use the URLScan 3.1 with your own custom rules, and it would come handy in situations like rejecting a request based on the User-Agent string.

Below is a sample rule for the same:

[Options]

RuleList=DenyUserAgent

 

[DenyUserAgent]

DenyDataSection=Agent Strings

ScanHeaders=User-Agent

 

[Agent Strings]

My Custom User-Agent String

Useful links

     http://learn.iis.net/page.aspx/476/common-urlscan-scenarios/

     http://blogs.iis.net/nazim/archive/2008/06/30/urlscan-v3-0-filtering-based-on-request-entity.aspx

     http://learn.iis.net/page.aspx/473/using-urlscan?info=EXLINK

Hope this helps!

Posted by rakkim | 5 Comments
Filed under:

IIS7 – Improved Backup Restore Tool, and a UI Module

NOTE : Before you even read about this module, I want to mention that I do not work for IIS product team at Microsoft, but in Product Support for IIS and ASP.NET. This module/application is purely out of my interest, and this is not an official release by Microsoft and hence NOT supported by Microsoft Services.

When I wrote my BackupRestore module UI module a while back, many people asked for few modifications, with the ability to take a complete backup of all the IIS configurations – because some of the IIS configurations can now lie within the individual web.configs of the applications. I was just waiting for some free time to do this. Since many of the users of this module have requested this feature for a while now, and I thought I would give a shot (and I wrote this while on vacation – that’s another story).

This is how it looks right now, and I’ve compiled a separate Windows Forms application as well – so if you do not want to put this module inside your IIS manager, you can use the Windows Forms Application version.

  image

Now, I’ve a checkbox which is selected by default which says the tool to collect the individual web.configs of the applications too. It generates the below files / folders inside the backup directory:

      • filelist.xml
      • webconfigfiles <folder>
      • other main config files and folders

So, the 1st 2 entries are the only difference between the backups taken using my previous module or APPCMD. filelist.xml is a file where I store all my backup files path (eg: path to the web.config of the website1), and it’s corresponding file in the <webconfigfiles> folder. This folder contains files in the name of 1.config, 2.config, etc which are the real web.config files of the applications.

Download Location

     IIS7 (7.5) manager UI module

    Windows Forms Application (stand alone EXE) (run with elevated permissions)

To use the IIS7 manager UI module, please follow the instructions in my older blog, but with the new DLL. I will soon add it to the iis.net/downloads under my user ID. If you have suggestions to improve this tool, please do leave a comment.

So, go ahead and grab the tool, and use it. Happy Backup-Restoring!

Posted by rakkim | 1 Comments
Filed under:

IIS7 - Getting HTTP 500.19 while accessing the website

I recently worked with one of my customer who was getting “HTTP 500.19” error while browsing the website.

Server Error in Application "application name"
HTTP Error 500.19 – Internal Server Error
HRESULT: 0x8007000d
Description of HRESULT
The requested page cannot be accessed because the related configuration data for the page is invalid.

Err tool showed “STIERR_INVALID_HW_TYPE” for 0x8007000d error code.

With further troubleshooting found that he had a virtual directory configured for a UNC share, and had a wrong password mentioned. Entered the proper credentials, and the problem went away.

This error message is a generic error message which would occur when the site configuration data present in the applicationHost.config has a malformed entry, or not a valid data (in our case it was the wrong password for the UNC connection, and the IIS cannot read its web.config file to check if there is any system.webserver setting mentioned)

Related KB : http://support.microsoft.com/kb/942055

Posted by rakkim | 2 Comments
Filed under:

IIS7 Tweet #2: Modifying an existing binding for the website

appcmd.exe set config  -section:system.applicationHost/sites /[name='Default Web Site'].bindings.[protocol='http',bindingInformation='*:80:'].bindingInformation:"*:80:www.test.com"  /commit:apphost

Posted by rakkim | 0 Comments
Filed under: ,

IIS7 Tweet #1 : Setting UploadReadAheadSize

appcmd.exe set config  -section:system.webServer/serverRuntime /uploadReadAheadSize:"491521"  /commit:apphost

Posted by rakkim | 1 Comments
Filed under: ,

Problems with rendering the "Design" View for a simple asp.net website from Visual Studio 2008

I recently worked with one of my customer who when clicking on the "Design" view of an ASPX page, the designer window doesn't appear - blank page appears. And if you minimize the VS window, and maximize it again - we will see the desktop background in the place of the Designer surface.

Verified that neither the "Microsoft Visual Studio Web Authoring Component" nor "Microsoft Web Designer tools" was installed on the machine (Control panel --> Add/Remove window components).

Ran the file [Path to the Installation DVD]\WCU\WebDesignerCore\WebDesignerCore.EXE

NOTE  :  This exe doesn't have a UI, so watch the Task Manager to know when this exe completes its installation.

Reference : http://forums.asp.net/t/1167590.aspx

Keywords : Visual Studio 2008 blank Design View hang

Posted by rakkim | 2 Comments
Filed under: , ,

ASP.NET - AJAX functionality not working on the page | Getting ‘Sys’ is undefined

When the ASP.NET AJAX Functionality is not working on a web page, it is usually due to the fact that the javascript needed for AJAX is not sent to the client from the server for some reason.

‘Sys’ is undefined. You might see this error message when there is a problem with the client in receiving the javascript sent by the server for the AJAX functionality. Some browser might not show an alert of this error message, and you might see the status bar saying done, but in yellow. Yellow always indicates that you have an error occurred while the page was getting loaded.

clip_image002

And, when you double click on the status bar, you will see the below window depending on the version of IE you are running:

clip_image004

Internet Explorer 8

clip_image006

Internet Explorer 7

Let’s go ahead, and look at the line of script reported in the error by opening up the HTML source(right click in the browser and choose view source) sent by the server to the client, and see what’s present at the line number 47, and char 1. You will see the below:

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Interestingly this is not something which you wrote yourself on the page, but this is added at the runtime by the ASPX handler which served your page, and this is done by the server side ScriptManager you have in your ASPX page.

If you search for ‘Sys’ in your HTML source, you might not find it. Because this is something which is sent to the client from a different file which is included in the HTML source. You might see the below (with a different value for the query string d) in the page:

<script src="/AJAXTimer/ScriptResource.axd?d=9tk5luWIQHpRBi2jvaLA3ovu_ryV3iBlv84cuaA3MT--_
            e3q9KdLubgmmRoMp9ixegSpkyQ0LFGM_KxDw2qwSneq8GS2D1TcTOujL7Q85DE1&amp;t=556b0a58" 
            type="text/javascript"></script>
So, a request to ScriptResource.axd is made in the runtime, and this is the file where all your javascripts required for your AJAX functionality to work and would be sent to the client as the response.

Let’s now see how to troubleshoot this problem we are facing. First thing to check is the IIS logs where all the requests with the corresponding response status would be logged. Below is the corresponding log for ScriptResource.axd on the server.

2009-02-26 21:00:28 W3SVC1 GET /AJAXTimer/ScriptResource.axd d=9tk5luWIQHpRBi2jvaLA3ovu_ryV3iBlv84cuaA3MT--_e3q9KdLubgmmRoMp9ixB0N1se3B9f-x_KQriM4xUb90HPABW5aUQb_PG3gbAH41&t=556b0a58 80 - 65.52.22.253 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322) royalchallenger 404 0 2 1405 567 15

So, we know for sure that the server is sending a HTTP 404 (Page not found) for the AXD request. Below are some possible reasons why a 404 might be sent from the server:

  1. File doesn’t exist on the server
  2. There is no ISAPI extension configured to serve this request
  3. An ISAPI filter plugged in the request pipeline sends a 404 for some reason
  4. URLScan rules might prevent it
  5. “Verify that file exist” is selected for the ISAPI extension configured to serve the request
  6. ISAPI Extension configured for the request (.axd in this example),is a prohibited web service extension

If you are running IIS7 (and above), you should consider using FREB for 404 errors, and from the logs you will be able to know which module is setting the 404.

If you check if there is a file named ScriptResource.axd is present in the website folder, I’m sure you will be surprised to see none. Because, ScriptResource.axd is a file which would be generated by the ASP.NET runtime on the fly, and would be sent to the client.

In one of plenty issues I’ve worked on AJAX, my customer was having a wild card ISAPI extension which on sight was advised for removal by me as a troubleshooting step, but only after taking a backup of IIS configuration. After removing the ISAPI extension, it started working – AJAX scripts are been sent to the client without any problem.

But the ISAPI extension which my customer had seemed to allow the ASPX requests to be processed by aspnet_isapi.dll, but it wasn’t allowing .AXD requests. It was the “Verify that file exists” causing the trouble because there is no physical file called ScriptResource.axd.

clip_image002[4]

If you are running into this problem, I would like you to check for the below things on the server.

  • Check if .axd requests are mapped to the aspnet_isapi.dll
    • In IIS6, you can check this in the Website properties --> Home Directory --> Configuration
    • In IIS7, you can check this in Website Features View --> Handler Mappings
  • Check if the web.config file has handler mappings added
    • In IIS6 or (IIS7 classic mode), you might need to place this under <system.web/httpHandlers>
    • In IIS7 (integrated mode), you might need to place this under <system.webServer/handlers>
<add verb="GET,HEAD" path="ScriptResource.axd" 
   type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0,
         Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />

You might also want to check this blog by Scott where he explains about xhtmlConformance, and problems of it with AJAX. You can choose to remove that line from the web.config, or can set the mode to “Transitional” instead of “Legacy”.

Posted by rakkim | 1 Comments
Filed under: , ,

VS2008 - Getting "Creating project 'projectname'... project creation failed"

Symptom

Cannot create a simple web application or a windows application project with Visual Studio 2008. Getting "Creating project 'projectname'... project creation failed"

Cause

Few packages are marked as skipped for loading

Resolution

Ran devenv /resetskippkgs which reset the skipped packages, and those would be loaded inside the devenv

 

Hope this helps someone wandering in the internet world in search of a solution! Thanks for stopping by!

Posted by rakkim | 1 Comments
Filed under: ,

IIS7 – Search the complete IIS configuration store – in which web.config is your attribute configured

As you know IIS 7.0 configuration system is huge, broad, or whatever you feel like calling it. It no longer just exist in its main configuration file applicationHost.config (like Metabase.XML in IIS 6.0). It can be widely spread in any of the web.config files in the virtual directories, or applications.

Today I had an interesting chat with my colleague on finding a tool to list down what are the web.config files available in a given website. I was suggesting the below code using MWA to just parse the configuration, and print if any VirtualPath of an application (virtual directory) has a file named web.config.

Update: The below sample doesn't list down the web.config's which are there in any physical folder which is not configured as an Application. So, you need to tweak your code a bit. Thanks to Vijay pointing this out.

Sample code snippet in C# listing down all applications, virtual directories available

ServerManager sm = new ServerManager();
foreach (Site s in sm.Sites)
{
    Console.WriteLine(s.Name + "\n");
    foreach (Application a in s.Applications)
    {
        foreach (VirtualDirectory v in a.VirtualDirectories)
        {
            try
            {
                string[] files = Directory.GetFiles(v.PhysicalPath);
                for (int i = 0; i < files.Length; i++)
                    if (files[i].EndsWith("web.config"))
                        Console.WriteLine(a + " has " + files[i]);
            }
            catch (Exception e)
            {
                // invalid physical path, so ignore :) 
            }
        }
    }
    Console.WriteLine("\n");
}
But, I wasn’t really thinking that there is a powerful module “Configuration Editor” which gives you an easy way to search for attributes, and know where they are configured (physical path of the web.config file). Below is a sample screenshot which shows the use of Search feature.
 
image
So, next time when you want to know where all the given attribute is configured, consider using Configuration Editor. Hope this helps!
Posted by rakkim | 1 Comments
Filed under:

ASP.NET – JSON – Serialization and Deserialization

I was looking around for a simple example which would just do a object serialization to a JSON format, and then deserializing back to the original object. I found few examples on MSDN, but did seem to be too long to try. Here I’ve given a simple code which would make your understanding easy, and simpler.
 
Before going into the code, let us first understand what is JSON, and what is its significance in the modern world of web applications.
 
What is JSON?
 
JSON is another format of expressing data, just like XML. But, JSON is very simpler than XML, and tiny than XML. So, it is becoming popular in the web world to choose the JSON notation over XML since JSON notation are usually shorter, and less data to be transmitted if at all they were to be.
 
Okay, I understood a little about JSON. Give me an example!
 
I know an example will get your understanding much better. Below is a simple example of how an object can be expressed in JSON notation. Let’s take a classical example of a Person object, and expressing myself as an object.
{
   “firstName”: “Rakki”,
   “lastName”:”Muthukumar”,
   “department”:”Microsoft PSS”,
   “address”: {
      “addressline1”: “Microsoft India GTSC”,
      “addressline2”: “PSS - DSI”,
      “city”: “Bangalore”,
      “state”: “Karnataka”,
      “country”: “India”,
      “pin”: 560028
   }
   “technologies”: [“IIS”, “ASP.NET”,“JavaScript”,“AJAX”]
}
In the above example, address is another object inside my Person, and technologies is an array or strings.
 
Express this as a simple .NET class, please!
 
Here is a simple example.
public class Address
{
    public string addressline1, addressline2, city, state, country;
    public int pin;
}
 
public class Person
{
    public string firstName, lastName, department;
    public Address address = new Address();
    public string[] technologies;
}
I get it. Now what? JSON Serialization / Deserialization?
 
I’m sure you do not want me to write what is serialization, and deserialization here. I’ll touch upon how to use System.Web.Script.Serialization.JavaScriptSerializer to convert an existing object into a JSON string.
JavaScriptSerializer js = new JavaScriptSerializer();
Person p1 = new Person();
p1.firstName = "Rakki";
p1.lastName = "Muthukumar";
p1.department = "Microsoft PSS";
p1.address.addressline1 = "Microsoft India GTSC";
p1.address.addressline2 = "PSS - DSI";
p1.address.city = "Bangalore";
p1.address.state = "Karnataka";
p1.address.country = "India";
p1.address.pin = 560028;
p1.technologies = new string[] { "IIS", "ASP.NET", "JavaScript", "AJAX" };
 
string str = js.Serialize(p1);

Above code just creates a Person object, and assign some values. Look at the last line where we are actually doing a serialization – means dumping the contents of the object to a JSON notation. Below is the string produced by the above code:

{"firstName":"Rakki","lastName":"Muthukumar","department":"Microsoft PSS","address":{"addressline1":"Microsoft India GTSC","addressline2":"PSS - DSI","city":"Bangalore","state":"Karnataka","country":"India","pin":560028},"technologies":["IIS","ASP.NET","JavaScript","AJAX"]}

It is the same as how we defined the object before – but in a single line. Now, you have successfully converted your object into a JSON string.

Now how do I deserialize it?
 
Before going into how to deserialize it, let’s just understand when you might want to deserialize the object. Classical example is a JSON object returned from a web service, or from your client side javascript code, and you will be able to deserialize it in the server side to use the received object. 
Person p2 = js.Deserialize<Person>(str);
Response.Write(p2.lastName);

p2.lastName would contain “Muthukumar” if your deserialization works fine. I suggest you to use the Deserialize<T> method since it will reduce the type casting you might be doing if you use DeserializeObject() method which returns a System.Object.

Hope this helps!

Posted by rakkim | 2 Comments
Filed under: , ,

Configuring IIS to advise the browser render on different IE modes

You would have already read IIS support team’s blog about configuring IIS to send an additional header to the client which would make IE to run under EmulateIE7 mode. I would also suggest you to read this MSDN article which talks about the various IE8 display modes available, and their corresponding functionality.

Here are the possible display modes and their corresponding value to be set for the “X-UA-Compatible” meta element (or for the same custom HTTP Header)

Emulate IE8 mode           -->   IE=EmulateIE8
Emulate IE7 mode           -->   IE=EmulateIE7
IE5 mode                         -->  IE=IE5
IE7 mode                         -->  IE=IE7
IE8 mode                         -->  IE=IE8
Edge mode                      -->  IE=Edge

Check this blog to know the syntax to add to your IIS6/IIS7 web servers. Make sure you read this MSDN article to understand the differences between the EmulateIE7 and IE7 mode – they are not just the same. There is an additional <!DOCTYPE> which will come to decide which mode to display when you use EmulateIE7 mode. This understanding is more important before you go ahead and make the changes to your web servers. So, make sure you know what you are doing!

Hope this helps!

Posted by rakkim | 0 Comments
Filed under: , , ,

IIS7 and Twitter – a love story

It is a while that I wrote something as crazy as this one is. This is basically a windows service running in your web server which would tweet often about the heart beat of the web server and posts its status messages. For example, v1.0 of this application will tweet the below (you can configure the time interval on the config file):

    • Total number of requests executing per application pool
    • Each Application pool Private bytes, and Virtual bytes memory usage
    • Server’s available Physical memory, and Virtual memory
    • Momentary Ping to a configured URL (example – http://localhost) (it will tweet only if it fails – for the moment I’m just checking if the HttpWebResponse.StatusCode != HttpStatusCode.OK. If time permits, I’ll try to add more granular control for the error codes)
    • If a request takes more than specified time limit to get served

There is a configuration file in which you can specify the Twitter Username, and password, time interval for each set of tweets, the URLs you want to monitor, and option to turn off the tweets.

image

For example, if a request is taking more than the configured time limit, it will tweet “Alert > /Default.aspx is being processed for 79s spending 79s IsapiModule | AppPool : Default Web Site” which will just say the URL, the time taken, which Module currently processes it, and the application pool serving the request.

 

Get IIS7TweetService to your server

  1. Download the Service EXE, and a sample config.xml which are inside the IIS7TweetService.zip file.
  2. Extract the contents to C:\IIS7TweetService (this location cannot be changed as I’ve hard coded the config file path. I’ll be allowing you to place it in some other folder in the future versions)
  3. Install the IIS7TweetService.exe as a Windows Service (from your Visual Studio Command Prompt run “installutil /i C:\IIS7TweetService\IIS7TweetService.exe”

Feel free to leave your comments in this blog, and your feature requests for the future versions if you like this one.

PS : I’ve only done a very limited testing on Vista and Windows Server 2008, so use it with caution. If I find time, I’ll try doing more testing and improve its efficiency. In case if you find a problem using this, please let me know. Your comments, and suggestions are most welcome.

Posted by rakkim | 0 Comments
Filed under: ,
More Posts Next page »
 
Page view tracker