A personal repository of technical notes. - CSC

How to Convert "File System" web site to "HTTP" web site in VS2005

Problem
Need to convert "File System" web site to "HTTP" web site in Visual Studio 2005.

For sample reason to convert, see "Server-Side Include "Failed to map the path"" CSC - Technical Notes. 24 Feb. 2009
http://csc-technicalnotes.blogspot.com/2008/12/server-side-include-virtual-failed-to.html.

Solution
1) Set up application in IIS for web site
- Directory: Select existing File System web site folder in solution

2) In IIS, set the directory to the existing File System web site folder in solution

3) Remove File System web site from solution
- Right-click File System web site in Solution Explorer
- Remove

4) Add HTTP web site to solution
- Solution Explorer/Right-click Solution/Add/Existing Web Site
- Add Existing Web Site Dialog/Click "Local IIS"
- Under "Local Internet Information Server", select virtual folder created above
- Open

5) Bind web site code to old VSS location
- VS2005/File/Source Control/Change Source Control
- Select HTTP web site from list
- Click "Bind" button
- Log into VSS if necessary
- VSS/Select project folder of old File System web site
- OK
- If Status = "Valid"
- OK
- Select "Allow these files to be replaced by their server versions"
- OK
- Done

- If Status = "Invalid",
- Cancel
- "Microsoft Visual Studio needs to reopen source control database connections for projects in the solution. Your source control provider may prompt for your credentials."
- OK

- NOTE: Performing 1 or more of the following tasks may enable the binding to be "Valid":
1: [This alone should work] Close VS and delete solution *.suo file.
2: Check one file from new web site into VSS. This will be created in a VSS default location.
3: Delete all files named "vssver.scc" in web site folders and sub-folders from Windows Explorer
- Retry steps under "Bind web site code to old VSS location"
- Delete project and file from VSS that was created during step "2:" above.
- This error may be thrown:
 Unexpected error encountered. It is recommended that you restart the application as soon as possible.
Error: Unspecified error
File: vsee\pkgs\vssprovider\abstractionlayerdispatcher.cpp
Line number: 4720

Visual Studio Remove "Find and Replace" "Find In Files" "Look In" MRU Entries

Problem
Need to remove obsolete items from most recently used (MRU) Find items in Visual Studio.

Solution
The entries are located at this registry location:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\ {Visual Studio Version} \Find

References
None

Xml.DocumentSource Will Not Load With Physical Path

Problem
ASP.NET Xml control will not load with physical path when XML file is not part of website. The following error is thrown:

Server Error System.Web.HttpException: 'c:\MyFolder\MyFile.xml' is a physical path.

Property System.Web.UI.WebControls.Xml.DocumentSource may not be a physical path to the requested XML file. It must be a virtual path that is a relative or root relative URL.

Solution
Tested on .NET Framework version 1.1.

1) Instantiate an XmlDocument using physical path.
2) Assign XmlDocument to Xml control

Example using a physical path:

<asp:xml id="xmlControl" transformsource="style.xslt" runat="server"></asp:xml>

...

protected System.Web.UI.WebControls.Xml xmlControl;

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load("C:\MyFolder\MyFile.xml");

xmlControl.Document = xmlDoc;


Example using a website path:

<asp:xml id="xmlControl" transformsource="style.xslt" runat="server"></asp:xml>

...

protected System.Web.UI.WebControls.Xml xmlControl;

xmlControl.DocumentSource = "/MyWebSiteFolder/MyXml.xml";


References
"Xml Class." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 20 Feb. 2009 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xml(VS.71).aspx

"XmlDocument Class." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 20 Feb. 2009 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument(VS.71).aspx

Make Property or Class Obsolete

Problem
Need to make class property obsolete so developers will not use it.

Solution
Set property to "obsolete" in code to cause a compile warning or error:
 [System.Obsolete("Deprecated: Don't use OldWay; use NewWay instead", true)]
public string Xxx
{
get
set
}
References
"Obsolete (C#)." MSDN: Microsoft Development, MSDN Subscriptions, Resources, and More. 18 Feb. 2009
http://msdn.microsoft.com/en-us/library/22kk2b44(VS.80).aspx.

Remove Connections from MRU of Visual Studio 2005 Copy Web Site Tool

Problem
Need to remove obsolete connections from most recently used (MRU) list of Copy Web Site Tool.

Solution

To remove a connection to a remote site that still exists:
1. From the Connect to list, select the connection that you want to remove.
2. Click the Disconnect from currently selected remote site button.
(MSDN)

To remove a connection to a remote site that no longer exists, edit contents of:
C:\Documents and Settings\[user name]\Local Settings\Application Data\Microsoft\WebsiteCache\[Web Site Name]\PublishState.xml

Remove obsolete <RemoteSite> sections and corresponding <PublishStatus> sections.

References
"How to: Copy Web Site Files with the Copy Web Site Tool." MSDN: Microsoft Developer Network. 12 Feb. 2009
http://msdn.microsoft.com/en-us/library/c95809c0(VS.80).aspx.

"Copy Web Site - how to remove connections from the list - ng.asp-net-forum.visual_web_developer_2005_express - error problem solve @CodeVerge." CodeVerge.Net - error problem solve @CodeVerge. 12 Feb. 2009
http://www.codeverge.net/ng.asp-net-forum.visual_web_developer_2005_express/copy-web-site-how-to-remove-connections-from-the-list.

"Re: How to remove a Connection from Copy Web Site list?" Tech-Archive.net: The source for usenet news. 12 Feb. 2009
http://www.tech-archive.net/Archive/VisualStudio/microsoft.public.vsnet.general/2007-06/msg00003.html.

Debug Class Library Apart From ASP.NET Solution

Steps to Debug a Class Library That is Not Part of a Visual Studio ASP.NET Solution

Prepare Class Library
- Open class library in Visual Studio
- Build class library in debug mode.
- Manually copy new debug DLLs from bin\debug folder of class library to bin folder of ASP.NET application that is using this class library
- Run web site in browser to rebuild with new dlls

Start Debug Session
- Set breakpoints in code of class library
- Select menu item Debug/Attach to Process...
- Transport: Default
- Attach to/Select...: Automatically determine the type of code to debug
- OK
- Available Processes:
    (If using IIS 6) Select aspnet_wp.exe
    (If using IIS 7) Check "Show processes from all users", check "Show process in all sessions", select w3wp.exe
- Note: There may be more than one. Hold mouse over each and select appropriate version.
- Attach

NOTE: if error, "EXECUTE permission denied on object 'sp_sdidebug', database 'master', owner 'dbo'."
-May "Attach to:" "Managed Code" instead of "Automatic: T-SQL code, Managed code".

NOTE: If error, "The breakpoint will not currently be hit. The source code is different from the original version."
-Need to get newer DLLs into web application. Redo steps under "Prepare Class Library"

NOTE: If error, "The breakpoint will not currently be hit. No symbols have been laoded for this document."
-Make sure "Attach to:" is set to one of the appropriate values listed above.
-Make sure class library was built in debug mode. See "Prepare Class Library" above.
-Open or refresh web page in which you are testing class library to rebuild site using new DLLs. See "Prepare Class Library" above.

Updates
2012-08-27 Added IIS 6 and IIS 7 notes.

Free Citation Web Sites

Problem
Need to accurately cite quoted sources.

Solutions
Use free cite making website

BibMe
Welcome to BibMe! The fully automatic bibliography maker that auto-fills. It's the easiest way to build a works cited page. And it's free.

"BibMe: Fast & Easy Bibliography Maker - MLA, APA, Chicago, Turabian - Free." BibMe: Fast & Easy Bibliography Maker - MLA, APA, Chicago, Turabian - Free. N.p., n.d. Web. 2 Aug. 2011.
<http://www.bibme.org/>.

EasyBib Free Bibliography Maker
The fastest way to create accurate, comprehensive works cited lists. 183,320,718 citations made to date. Now with Autocite: Cite books with just an ISBN number, and websites with just a URL.

EasyBib: Free Bibliography Maker - MLA, APA, Chicago Citation Styles. Web. 02 Aug. 2011.
<http://www.easybib.com>.

See Also
"Kinds of Sources and How to Cite Them | Using Sources | Writing at Yale | The Writing Center | Yale College." Yale University. Web. 22 Jan. 2010.
<http://www.yale.edu/bass/writing/sources/kinds/index.html>.

Updates
2011-08-02 Added BibMe reference.

ConfigurationManager.GetSection() as NameValueCollection Example

Problem
Need a custom AppSettings section in config file.

Solution
Create a custom section in config file based upon AppSettingsSection. Then use NameValueCollection to handle settings. See ConfigurationManager GetSection example below.

Note: Tested in .NET 4.0 and 2.0. If using 2.0, change the version number of type in config from 4 to 2.

<?xml version="1.0"?>
<configuration>
       <configSections>
              <sectionGroup name="customAppSettingsGroup">
                     <section name="customAppSettingsAAA" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                     <section name="customAppSettingsBBB" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                     <section name="customAppSettingsCCC" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
              </sectionGroup>
       </configSections>
       <customAppSettingsGroup>
              <customAppSettingsAAA>
                     <add key="KeyOneAAA" value="ValueOneAAA"/>
                     <add key="KeyTwoAAA" value="ValueTwoAAA"/>
                     <add key="KeyThreeAAA" value="ValueThreeAAA"/>
              </customAppSettingsAAA>
              <customAppSettingsBBB>
                     <add key="KeyOneBBB" value="ValueOneBBB"/>
                     <add key="KeyTwoBBB" value="ValueTwoBBB"/>
                     <add key="KeyThreeBBB" value="ValueThreeBBB"/>
              </customAppSettingsBBB>
              <customAppSettingsCCC>
                     <add key="KeyOneCCC" value="ValueOneCCC"/>
                     <add key="KeyTwoCCC" value="ValueTwoCCC"/>
                     <add key="KeyThreeCCC" value="ValueThreeCCC"/>
              </customAppSettingsCCC>
       </customAppSettingsGroup>
</configuration>

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Web.Configuration;

public partial class ProofOfConcept_Configuration_Default : System.Web.UI.Page
{
       protected void Page_Load(object sender, EventArgs e)
       {
              StringBuilder outputStringBuilder = new StringBuilder();

              // EXAMPLE 1: Retrieve 1 custom appsettings section.

              // ConfigurationManager.GetSection() as NameValueCollection example
              // Create a custom AppSettings section in config file
              NameValueCollection settingsAAA = ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsAAA") as NameValueCollection;
              if (settingsAAA != null && settingsAAA.Count > 0)
              {
                     // Individual setting
                     outputStringBuilder.AppendLine("Individual setting ----------");
                     outputStringBuilder.AppendLine(settingsAAA["KeyTwoAAA"]);

                     // All settings Values in section
                     outputStringBuilder.AppendLine("All settings values in section ----------");
                     foreach (string key in settingsAAA.AllKeys)
                     {
                           outputStringBuilder.AppendLine(settingsAAA[key]);
                     }

                     // All settings' Keys and Values to GridView via Dictionary.
                     Dictionary<string, string> outputDictionary = new Dictionary<string, string>(settingsAAA.Count);
                     outputDictionary.Add("[Dictionary to GridView]", "[Example]");
                     foreach (string key in settingsAAA.AllKeys)
                     {
                           outputDictionary.Add(key, settingsAAA[key]);
                     }
                     MainGridView.DataSource = outputDictionary;
                     MainGridView.DataBind();
              }

              // EXAMPLE 2: Put multiple custom appsettings sections into a single Dictionary collection.

              Dictionary<string, NameValueCollection> settingsDictionary = new Dictionary<string, NameValueCollection>();

              settingsDictionary.Add("customAppSettingsAAA", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsAAA") as NameValueCollection);
              settingsDictionary.Add("customAppSettingsBBB", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsBBB") as NameValueCollection);
              settingsDictionary.Add("customAppSettingsCCC", ConfigurationManager.GetSection("customAppSettingsGroup/customAppSettingsCCC") as NameValueCollection);

              outputStringBuilder.AppendLine("Dictionary items ----------");
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsAAA"]["KeyTwoAAA"]);
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsBBB"]["KeyOneBBB"]);
              outputStringBuilder.AppendLine(settingsDictionary["customAppSettingsCCC"]["KeyThreeCCC"]);

              // EXAMPLE 3: Loop through each setting of each section in a group

              Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~/ProofOfConcept/Configuration"); // NOTE: MUST INCLUDE FULL PATH TO SUBFOLDER OF WEB.CONFIG IF NECESSARY
              ConfigurationSectionGroup myGroup = webConfig.GetSectionGroup("customAppSettingsGroup");
              outputStringBuilder.AppendLine("Loop through entire group ----------");

              foreach (ConfigurationSection section in myGroup.Sections)
              {
                     outputStringBuilder.AppendLine(section.SectionInformation.SectionName);
                     NameValueCollection settings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
                     foreach (string key in settings)
                     {
                           outputStringBuilder.AppendLine(String.Format(" {0} = {1}", key, settings[key]));
                     }
              }

              MainLiteral.Text = outputStringBuilder.ToString();
       }
}

Sample Output

Individual setting ----------
ValueTwoAAA
All settings values in section ----------
ValueOneAAA
ValueTwoAAA
ValueThreeAAA
Dictionary items ----------
ValueTwoAAA
ValueOneBBB
ValueThreeCCC
Loop through entire group ----------
customAppSettingsGroup/customAppSettingsCCC
 KeyOneCCC = ValueOneCCC
 KeyTwoCCC = ValueTwoCCC
 KeyThreeCCC = ValueThreeCCC
customAppSettingsGroup/customAppSettingsAAA
 KeyOneAAA = ValueOneAAA
 KeyTwoAAA = ValueTwoAAA
 KeyThreeAAA = ValueThreeAAA
customAppSettingsGroup/customAppSettingsBBB
 KeyOneBBB = ValueOneBBB
 KeyTwoBBB = ValueTwoBBB
 KeyThreeBBB = ValueThreeBBB

KeyValue
[Dictionary to GridView][Example]
KeyOneAAAValueOneAAA
KeyTwoAAAValueTwoAAA
KeyThreeAAAValueThreeAAA


Updates
2020-04-01 Added example 3: Loop through each setting of each section in a group
2014-05-23 Added example: All settings' Keys and Values to GridView via Dictionary.
2013-12-05 Added Example 2.
2013-11-11 Updated example code.

CGI Timeout IIS 6.0

Problem
CGI Timeout
The specified CGI application exceeded the allowed time for processing. The server has deleted the process.

See
The specified CGI application exceeded the allowed time for processing.
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/w2000Msgs/1367.mspx?mfr=true

Solution
To increase timout:
1) Enable the Metabase Edit-While Running setting.
2) Locate metabase file:
C:\WINDOWS\system32\inetsrv\MetaBase.xml
3) Backup metabase file.
4) Edit metabase file with Notepad.
5) To double timeout value from default 5 minutes to 10 minutes, change CGITimeout="300" to CGITimeout="600".
6) Save.

References
Enabling Edit-While-Running in IIS 6.0 (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e6c04028-7db3-4564-9912-04e82c52d5ca.mspx?mfr=true

Editing the Metabase (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e643878b-67ea-4bf9-a9fd-3245b1baed64.mspx?mfr=true

CGITimeout Metabase Property (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/c49c897e-7afa-4963-aa39-dd03920c1e9c.mspx?mfr=true

Configuring CGI Application Timeouts (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1cc829e2-a9fe-4885-b0a5-43a6d14e1961.mspx?mfr=true

Overview of the IIS 6.0 Metabase (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/6929e089-c495-4ac8-8db0-b069b349b7ba.mspx?mfr=true

Delete SQL SERVER Database Transaction Log

Problem
- Unable to modify table.
The transaction log for database 'MyDatabase' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases

Solution
For detailed log backup solutions, see links under References below.

To delete an unneeded log on a development server:

BACKUP LOG MyDatabase WITH TRUNCATE_ONLY
DBCC SHRINKFILE(MyDatabase_Log, 2)


To determine log file name used as parameter with SHRINKFILE:

In Microsoft SQL Server Management Studio
  1. Right-click Object Explorer/MyDatabase
  2. Click Properties
  3. Click Select a page/Files
  4. See Database files: for name of log file.

References
BACKUP (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms186865(SQL.90).aspx

DBCC SHRINKFILE (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms189493(SQL.90).aspx

Troubleshooting a Full Transaction Log (Error 9002)
http://msdn.microsoft.com/en-us/library/ms175495(SQL.90).aspx

How to use the DBCC SHRINKFILE statement to shrink the transaction log file in SQL Server 2005
http://support.microsoft.com/kb/907511

SQL SERVER - Shrinking Truncate Log File - Log Full « Journey to SQL Authority with Pinal Dave
http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/

The transaction log for database 'mydatabase' is full. To find out why space in the log cannot be reused, see the log_reuse_wait : Transact-SQL : SQL Server : MSDN Forums
http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/f3467f88-8657-439f-b422-00e4a0dd14ab/