Troubleshooting your ASP.NET Environment to Run AJAX in IIS 7.5

After you have created that ASP.NET website of yours and are ready to deploy it on your server (home, company or hosting), you may soon realize that you cannot run any of the AJAX examples (especially in Chrome browser) without using a web server like IIS. You may also require some additional configuration in IIS to run ASP.NET code.

Follow these steps to make sure that you set up your Environment appropriately to run ASP.NET websites on IIS. I am using IIS 7.5 on a Windows 7 machine with Visual Studio 2012. The same process will work even for Visual Studio 2010 with ASP.NET 4.0.

Step 1: The first step is to make sure IIS is installed on your machine. Go to the Control Panel\Programs\Programs and Features and click ‘Turn Windows Features on or off’. This brings up a Windows Features list. Check the ‘Internet Information Services’ checkbox if it is unchecked


Step 2: In order to check if IIS has been installed on Windows 7, go to Start > Run. Type inetmgr and press OK. You will get an IIS configuration screen if IIS is installed. Alternatively you can also go to ControlPanel > Add Remove Programs > Add Remove Windows Components and look in the list of installed components for IIS.

Step 3: With IIS setup, open IIS (Run > inetmgr), Right click ‘Sites’ to add a new website. Give the site a name, use the ASP.NET v4.0 application pool, browse to the direction where you have saved your website code and specify a port.


That’s it. In the Actions pane on the right hand side, use Browse Web Site link to browse your site.

Registering ASP.NET with IIS

If IIS was previously enabled on the computer before installing Visual Studio or installing the .NET Framework, the setup automatically registers ASP.NET with IIS. However, if IIS was enabled after you installed Visual Studio or the .NET Framework, you must run the ASP.NET IIS Registration tool in order to register the .NET Framework with IIS and create application pools that use the .NET Framework. So if you run a website in IIS and get the HTTP Error 404.3-Not Found exception or you cannot find the ASP.NET v4.0 application pool while adding a website, you probably do not have registered ASP.NET applications with IIS.


Use the ASP.NET IIS Registration tool (Aspnet_regiis.exe) to register ASP.NET applications with Internet Information Services (IIS). To use this tool, either go to %windir%\Microsoft.NET\Framework\v4.0.30319 or just open the Developer Command Prompt for VS. Make sure to Run as Administrator


Now you can type aspnet_regiis.exe –i in the Console window and execute the command. You are all set!


 Step 4: If you are serving .json files via IIS, there’s one more step you need to perform to avoid getting the “Failed to load resource: the server responded with a status of 404 (Not Found)” error. The reason you get a 404 error for .json files is that IIS is not configured to serve files that aren't of a MIME type that it knows about.

So you need to explicitly add a MIME type to IIS to allow it to serve that type of file, in our case .json. To do so, in IIS Manager, click MIME Types. Click "New". Enter "JSON" for the extension and "application/json" for the MIME type as shown below:


5. The folder/files of the sample needs to have read permissions for Network Service user or Application pool Identity user. You can find the application pools identity by going to IIS Manager > Application Pools > Select a Pool (in our case ASP.NET v4.0) > Advanced Settings > Process Model > Identity.

That pretty much sets up your development environment to run ASP.NET websites using AJAX.

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: