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

install-iis

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.

 add-site-iis

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.

 .net-fw-install-error

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

 vs-command-prompt

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

 aspnet-regiis

 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:

 add-mime-type

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.

Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: