I strongly recommend developing by pointing to local IIS server, because IIS is the way your application is going to be served to end users. Otherwise there will be scenarios of "works on my machine" which is really tough to deal with.
Debugging IIS hosted Web Forms Unit test
By default if we put a break point in ASP.Net Web Forms unit test where the site is hosted in IIS, it wont get hit. We need to attach to IIS process w3wp.exe.
So put a Debugger.Break or Debugger.Launch. This will open up an error dialog and from there we can attach to W3WP.exe.1
Also need to make sure that the dlls are compiled in debug mode.
Issues
Sometime there may be issues when running the unit tests. One error what I faced was below.
The URL specified ('http://localhost/joymononline') does not correspond to a valid directory. Tests configured to run in ASP.NET in IIS require a valid directory to exist for the URL. The URL may be invalid or may not point to a valid Web application
There are multiple reasons for this.
First we need to run Visual Studio in admin privilege.
Second we need check whether the below entry is logged into event log viewer -> application node
(QTAgent32_40.exe, PID 12920, Thread 14) WebSites.GetWebServer: failed to create AspNetHelper: Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The website metabase contains unexpected information or you do not have permission to access the metabase. You must be a member of the Administrators group on the local computer to access the IIS metabase. Therefore, you cannot create or open a local IIS Web site. If you have Read, Write, and Modify Permissions for the folder where the files are located, you can create a file system web site that points to the folder in order to proceed. ---> System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_WebServerOrdinal()
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_RootPath()
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_PhysicalPath()
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelperMan..ctor(Uri uri, BasicAuthCredential credential, Int32 frameworkMajorVersion)
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelperMan..ctor(Uri uri, BasicAuthCredential credential)
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelper.Create(Uri uri, BasicAuthCredential credential)
at Microsoft.VisualStudio.TestTools.HostAdapters.WebSites.GetWebServer(String webServerName, WebServerType webServerType, String urlToTest, String pathToWeb, String webAppRoot, BasicAuthCredential credential, Context context, WebSiteConfigurationType webSiteConfigType, Origin origin)
If we can see the above, we can try enabling IIS 6 compatibility. This is applicable if we are running on Windows 7 with IIS 7 or above.
Go to
Control Panel->Programs and Features->Turn Windows Featuers On or Off
Then
Internet Information Services->Web Management Tools->IIS 6 Management Compatibility
Tick the "IIS Metabase and IIS 6 configuration compatibility" option and install it.
Some users says that we need to enable everything in IIS 6 Management Compatibility.
2