IIS7

...now browsing by category

 

Fixing error “..an attempt was made to load a program with an incorrect format.”

Tuesday, April 14th, 2015

For a few hours I had been struggling with this error message when I tried to launch a WCF service (MyProductService.svc) from IIS7 hosted site:

Could not load file or assembly 'SomeExistingDotNetAssembly' or one of its dependencies. An attempt was made to load a program with an incorrect format.

The assembly was not built on my 64-bit machine initially so I suspected there must be something to do with that. After many failed internet searches, I decided to search for the detail error message below:

System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12857578
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +148
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

 

And that finally got me to a post from Stackoverflow which had these sacred words in it:

 Bad Image Format Exception usually means you tried to load a x64 Assembly / native DLL into an 32Bit process or vice versa a 32Bit Assembly into an x64 Process.

I felt I was close to hitting the jackpot! Then another user’s comment on IIS Application Pool setting settled the win for me:

 ...go into your IIS 7 manager console, find the application pool your app is running in, right-click on it, go to Advanced Settings, and change the Enable 32-bit Applications setting to true

And that was all it take to clear my error; after that change on the Application Pool, I clicked my “MyProductService.svc” again and now it rendered the wsdl xml nice and clean.

I am so grateful to these folks who shared and spent time to answer questions. So I reminded myself to do the same whenever I could.

How to clear the error “ExtensionlessUrlHandler-Integrated-4.0″ has a bad module “ManagedPipelineHandler” in its module list

Monday, December 22nd, 2014

Started with another MVC4 web application that requires Https today and got this error when I tried to browsed the app from local IIS 7:

ExtensionlessUrlHandler-Integrated-4.0″ has a bad module “ManagedPipelineHandler” in its module list

Thanks to this post at http://www.brandonmartinez.com/2014/07/02/resolve-an-http-error-500-21-in-iis/ and followed the instruction to run
regiis, I was able to clear this error and successfully browsed to the local site’s landing page. Here were what I went through (I was on a Win7 x64 bit machine):

  1. All Programs -> Visual Studio 2012 -> Visual Studio Tools
  2. Right clicked on the “Developer Command Prompt for VS2012″ selected “Run as administrator“; this was a must or the next step would not be executed.
  3. Went to directory at C:\Windows\Microsoft.NET\Framework64\v4.0.30319 and ran this command line: aspnet_regiis.exe -i
  4. The whole thing should look like this after done:
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -i
    Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408
    Administration utility to install and uninstall ASP.NET on the local machine.
    Copyright (C) Microsoft Corporation.  All rights reserved.
    Start installing ASP.NET (4.0.30319.18408).
    ....
    Finished installing ASP.NET (4.0.30319.18408).
    
  5. After that, I went back to IIS and re-started the website (which was assigned to a port 44300 for https) then browsed to the landing page and now everything looked pretty.

DotNetNuke Portal Setup

Tuesday, March 12th, 2013

Steps to get DNN installed on VM and run:

  1. Downloaded DNN Install version from here http://dotnetnuke.codeplex.com/releases/view/81081. Did New Install, not “Install and Source Codes” for now.
  2. Created database DNN on VM Local machine SqlExpress and gave it full access to “Network Service” and my Windows Account
  3. Opened web.config from c:\Development\Dotnetnuke folder (where the dnn installation zip files were extracted to)
    and changed the connectionstring from:<add name=”SiteSqlServer” connectionString=”Server=(local);Database=DotNetNuke;uid=;pwd=;” providerName=”System.Data.SqlClient” />

    to:

    <add name=”SiteSqlServer” connectionString=”Data Source=LocalMachineName\SQLEXPRESS;Initial Catalog=DNN;Integrated Security=True”
    providerName=”System.Data.SqlClient” />

  4. Then went to IIS7/Default websites and added a new virtual directory, DNN and pointed to physical folder at c:\Development\DotNetNuke; Right clicked on the DNN VD and converted it to Application.
  5. Once converted to Application, I could set it to use the application pool that is specific to this app.
  6. So, went back to Application Pools and created one, “DNN” and changed Framework version to 4.0 and leave the Managed Pipeline Mode to
    default, “Integrated” and under the Process Model set the Identity to use Network Service instead of the default “ApplicationPoolIdentity”. The
    reason was that I could assign full folder access permission to the “Network Service” user account, but “ApplicationPoolIdentity” is not a
    actual Windows account.
  7. Set the Application pool to this newly created “DNN” ap.
  8. Browsed the site from IIS and just followed the onscreen instruction to go through the installation process. The database tables and objects
    are all created during this process. No need to run any sql installation script from Sql server side.

ASP.NET Web service call error, “Unable to generate a temporary class (result=1)”

Tuesday, February 19th, 2013

Got this obscure error while calling a web service method that requires a Xml serializer:

Unable to generate a temporary class (result=1).\r\nerror CS2001: Source file ‘C:\\Windows\\TEMP\\qdrb02m1.0.cs’ could not be found\r\nerror CS2008: No inputs specified\r\n”}  System.Exception {System.InvalidOperationException} “

 

Web searches on key phrase “Unable to generate a temporary class (result=1)” returned some useful results but none could directly resolve my issue. But general direction was pointing to the proper permission of the ASP.Net surrogate identity that most likely does not have sufficient right to the local I/O where XML serialization takes place.

To prove this, I fired up a console application and called the same web service method; as anticipated, the Console app did not throw error at all. So that’s true – it is to do with the Windows account that IIS uses to run the ASP.Net process.

By default, IIS7 uses “ApplicationPoolIdentity” as the Identity for the Application pool automatically created when a new website is added to the IIS/Sites. But what’s underneath this mysterious “ApplicationPoolIdentity” – you could not even find it in Windows by looking up user accounts? Below are several things I tried and let’s see how they fared:

  1. I tried to give “Full Control” permission to ASP.NET Machine Account on c:\windows\Temp folder. Not work.
  2. Changed the app pool identity to “Network Service” (via IIS7/Site/Advanced Settings) and gave the “Network Service” full control permission to c:\windows\temp (via Windows Explorer). It worked! Then I reduced permission to only “Read, List Folder Contents”, and it still worked.
  3. Changed the app pool identity to “Local System”, of course that worked too.

 

So, at the end, to get rid of error “Unable to generate a temporary class (result=1)..”,  I ended up using the “Network Service” as the Application Pool identity (leave the security mode as Integrated) and granted the “Network Service” account permission “Read, List folder contents” on “C:\Windows\Temp” folder.

P.S.: after I deployed the web app to my staging web server, the error returned. The staging server is running IIS6 and the app pool identity by default was already tied to “Network Service” account. So I went directly to the c:\windows\temp folder and as I anticipated, the account did not have “read, list folder contents” permission. So I granted the permission to “Network Service” account and then it all worked!

Add a website to local IIS7 and browse to it with friendly name

Tuesday, October 2nd, 2012
  1. Launched IIS7 -> Sites -> Add Web Site
  2. Entered yangsoft.com; left application pool with default name
  3. Mapped to physical path H:\Development\yangsoft.com\Yangsoft.Web
  4. Pick a unassigned port: 8092
  5. Host name: yangsoft.com (hopefully, this will precede the real domain name, once the entry is made into hosts file)
  6. After exiting IIS7, browsed to C:\Windows\System32\drivers\etc and opened the hosts file with notepad
  7. Added this entry: 127.0.0.1 yangsoft.com and saved.
  8. Browsed to http://localhost:8092 but get a bad request error 400: invalid hostname
  9. Returned to IIS7 and changed App Pool Identity “yangsoft.com” to use .net 4.0 and Integrated Mode. By default, whenever a website was first setup, it uses .net v 2.0
  10. Now go to browser and type in :yangsoft.com:8092 and it brought up the local site that is in development folder, not in the deployed folder.
  11. In order to launch the website from VS 2010 IDE in the same fashion, I went into VS2010 web project properties and changed the Servers setting from “Use Visual Studio Development Server” to “Use Local ISI Web server” and pasted in the url: yangsoft.com:8092
  12. Ran the project in debug mode and now the website rendered as http://yangsoft.com:8092/Default.aspx instead of the http://localhost:2236/Default.aspx or whatever random port number the IDE picks for you.

Installed WordPresss to Local IIS7

Monday, February 13th, 2012

Before my memory evaporates again, let’s write down the steps on how this was done:

  1. Downloaded and Installed MySql database engine, then the Workbench (acts like SQL Server Management Studio). No need to write down the version; you will always to go their site to get the latest.
  2. I already installed PHP engine the other day so no need to redo it; this time around, just go to WordPress site http://www.wordpress.org and grabbed the latest .zip file, expanded to D:\Download\Wordpress
  3. Went to IIS7 Manager and added a new site, called “wordpress” and set the physical path to d:\download\wordpress, let the site use default ApplicationPool Identity, wordpress; and set binding to port 8089 and host name “blog.yang.com”.
  4. Before I could browse to http://blog.yang.com:8089, I needed to update the local host file; to do so, browsed to c:\windows\system32\drivers\etc\hosts. The file was not editable by default; so I opened the file property and gave myself  full control permission, changed the entry there from 127.0.0.1 blog.yangsoft.com to blog.yang.com; if the entry is not there, just add one.
  5. Before I could run wp install, I needed to create a database on local mysql server. I launched MySQL WorkBench 5.2 CE ->Server Administration ->File -> New Model. Once I clicked on New Model from File menu, it automatically created a MyDB, clicked on Edit schema and changed name to myblog, selecting collation to be UTF8-UTF8_General_CI.
  6. Added a mysql user account and gave it full db rights.
  7. It is almost there. Now I went to d:\download\wordpress and opened wp-config-sample.php, replaced DB related settings to point to localhost, db name “myblog” and the newly created username. Now I was ready to run WP install, the famous 5 minutes no-brainer!
  8. Went to IIS7, browsed to wordpress/wp-admin/install.php, and it was truly amazing it did only take about 5 minutes to get the site up and running!

Deploy .Net 4.0 Website to Local IIS7

Wednesday, January 18th, 2012

I had a website that was upgraded from .Net 2.0 to v.4.0; normally I used Web Deployment Project to pack it and deploy to remote IIS6 server using xcopy and had not encountered the need to deploy to local IIS which is IIS7 now. Today I did, and ran into a few errors before getting it to run, so I recorded the steps and fixes here to refresh myself and help others from being hassled by these again:

  1. Used Web Deployment Project to deploy the solution (Output Assemblies setting: Merge all outputs to a single assembly and Treat as library component checked)
  2. I did not check the “Create an IIS virtual directory for the output folder option as I wanted to create the website manually.
  3. Opened IIS7 and added a new website, called it “NewAdmin”; went to binding and changed port to 8081 as other default ports were already taken by other sites; left the application pool to use the default one created by the system.
  4. By default every new site created in IIS7 uses ASP.Net v2.0, obviously, changed that to .Net v.4.xxxx, and left the Integrated mode and ApplicationPoolIdentity unchanged.
  5. Now browsed to the site and got this error, “There is a duplicate ‘system.web.extensions/scripting/scriptResourceHandler’ section defined”, and some more, “There is a duplicate ‘system.web.extensions/scripting/webServices/jsonSerialization’ section defined”..
  6. Googled and read postings from here, and led me to doing the next step
  7. Removed these sections from the sectionGroup:<section name=”scriptResourceHandler” type=”System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication”/><section name=”jsonSerialization” type=”System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”Everywhere”/>
    <section name=”profileService” type=”System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication”/>
    <section name=”authenticationService” type=”System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication”/>
    <section name=”roleService” type=”System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” allowDefinition=”MachineToApplication”/>

     

  8. Browsed to the site again, a different error was displayed “The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.” what’s going on?
  9. Well, actually this should have been done in step 3) – I need to lift the ISAPI and CGI Restrictions on the site just created. By default, IIS7 shutdowns everything; this is far different from IIS6 and earlier version, so be aware!
  10. Went back to local host node, clicked on Features View, then double clicked on ISAPI and CGI Restrictions – saw that By default ASP.Net v4.0.30319 was restricted. Changed that to “Allow”.
  11. That’s it.

NT AUTHORITY\NETWORK SERVICE does not have write access to ‘..\Temporary ASP.NET Files’.

Wednesday, January 4th, 2012

Got this error while trying to browse to a WCF service from IIS7: The current identity (NT AUTHORITY\NETWORK SERVICE) does not have write access to ‘D:\WINDOWS\Microsoft.NET\Framework\v4.0.3019\Temporary ASP.NET Files’. 

What happened? There must be some recent Windows updates to IIS7 that had messed up the previously security settings, but this was just my guessing. Important thing was how to fix this quickly. Found a post here granting access to IIS configuration and other directorys used by ASP.Net, and executed this line of command:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -ga “NT Authority\Ne
twork Service”

And that took care of it. “Network Service” is the identity used by the Application Pool used by the WCF service.

Allow other machine to connect to WCF Service hosted on localhost, Win7/IIS7

Thursday, November 10th, 2011

Moving along with my WCF project; today I needed to connect to the WCF services developed and published to my development machine (localhost, let’s mask its name as “dev1″) from another machine, named “user1″,  in the same network domain, and got the “Operation timed out” error 118. My localhost machine is a Windows 7 Enterprise and the WCF services are hosted on IIS7. Obviously, this was a security setting on the firewall on local machine that had blocked remote access.  Below are the steps I went through to get the problem resolved:

  1. First, I checked if I had access to default port, 80 at dev1 from user1 before I did anything; I browsed to http://dev1/Defaultsite/Default.aspx, and fair enough, not a chance – page was not rendering.
  2. On localhost (dev1), I went to Control Panel -> System and Security -> Windows Firewall -> Allowed Programs; highlighted “World Wide Web Services (HTTP) and changed settings -> checked “Domain” and “Home/Work (private)” checkboxes.
  3. Now browsed to http://dev1/Defaultsite/Default.aspx again and it worked!
  4. But when I browsed to a different port at dev1, http://dev1:8088/WcfHost/Service1.svc, I got denied again, error 118, “The operation timed out”, scary..I thought that I might need to turn on Windows Communication Foundation allowed programs inside Windows Firewall; so I did that but then it sill not worked.
  5. Is this WCF issue or port opening issue? To test that, I created a plain website, TestWeb, and hosted at http://dev1:8088/Testweb, and it still cannot be accessed from “user1″ machine. So this must be that port 8088 is not accessible from another machine.
  6. Back to Windows firewall config tool and went to Advanced Security Settings and created a new inbound connection rule, “RemoteAccessToPort8088″ to allow remote connection to port 8088 and 444.
  7. And this did it! Now I was able to access both http://dev1:8088/WcfHost/Service1.svc and https://dev1:444/WcfHost/Service1.svc from “user1″ machine.

Run .Net 1.1 Web Project in Windows 7/IIS7

Tuesday, November 1st, 2011

I have to develop and support three versions of .Net projects on one Windows 7 machine running IIS7. After installing VS2003, VS2008 and VS2010 on the machine, it was not without some struggling to get the legacy .Net 1.1 project to run seamlessly in IIS7, so it is worthwhile to write down a few key steps here:

  1. Created a .Net 1.1 website, called Net1_1 in IIS7 and selected Application pool ASP.Net 1.1 from the available Application pool drop-down. The ASP.Net 1.1 application pool was created automatically when Framework 1.1 was installed. If this application pool is not present, that is an indication that .Net 1.1 framework has not been installed or was not installed properly.
  2. Made sure that the ASP.Net 1.1 app pool “Managed Pipeline Mode” is “Classic”, which is default, instead of “Integrated”.
  3. At this point, I tried to browse to the .Net 1.1 app directly from IIS7, I got all sort of errors. They were caused by that ISAPI filter for .Net 1.1 was not  present by default in IIS7. To fix that, I selected the Net1_1 site -> Features View and double-clicked on “ISAPI Filters” icon; clicked on Add, gave it a name “Asp.Net 1.1″ and set “Executable” to be “C:\Windows\Microsoft.NET\Framework\v1.1.4322\aspnet_filter.dll”.
  4. Lifted the ISAPI and CGI restriction on the filter by going in to ISAPI and CGI Restrictions pane (accessed from Machine level Feature View) and changed Restriction from “Not Allowed” to “Allowed”.
  5. Almost done; I still got “Access denied” error after all these, why? Googled for “running .net 1.1 on IIS7″ and found a useful post at http://blogs.iis.net/rakkimk/archive/2008/03/20/iis7-running-asp-net-1-1-applications.aspx, which pointed me to download and install .Net framework 1.1 service pack 1. After that, I was able to bring the .Net 1.1 site back to live in IIS7!
  6. Another error, “Error while trying to run project: Unable to start debugging on the web server. Access is denied.”, arose when I tried to debug the .Net 1.1 project from VS2003. What’s going on? Well, it’s the notorious Windows 7 “Run as Administrator” thing! I had to run VS 2003 as administrator, open the project from VS2003, and then the error went away. What an inconvenience!