remove virtual directory in IIS Express created in error - asp.net

I clicked on create virtual directory of the web tab of the properties menu.
My application now isn't running (the published version is)
It just hangs when any of my controllers code is executed
I think I've messed up the IIS config
Can anyone help me out?

My file was located here:
C:\Users\YourUserName\Documents\IISExpress\config\applicationhost.config
Entries will look like this
<application path="/virtualDirectoryName" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\projects\Project1" />
</application>

None of this worked for me - possibly because I'm working with a later version of the tools (VS 2017). I finally found the correct appplicationhost.config file in the .vs directory for the solution, edited it, rebooted, and it worked.

If you created another virtual directory by mistake, go to your .vs folder inside your solution/project folder and look for a file called: applicationhost.config and change/fix what is inside the tag:
<sites>
<site name="YourSite" id="1">
...
</site>
...
</sites>
Hope this helps! :D

I realize this has been answered a few times over, but had this exact same issue in VS 2019 so I performed the following steps:
Closed the Solution
Navigated in the file system to the .vs folder within my solution and deleted it
Reopened Solution and rebuilt.
Upon reopening the solution and Starting the project, it appeared to have worked without any sort of reboot.
Some may consider deleting the .vs folder destructive in some way but given the fact it's normally excluded from most (if not all source control systems) there isn't really anything mission critical in there and it all gets rebuilt anyways.

I faced the same issue today. The simplest way to deal with this is just simply change the Port number. Go to the Properties of the Project which you have made as Startup Project.
Then...
Click to view => Step 1
Let's say the initial port number is 62168. Just increment it by 1.
Click to view => Step 2
And create a new virtual directory. Now execute the project again. This time it'll work.
Steps:
Go to Properties window of the project selected as the StartUp Project
Select the "Web" section present in the LHS of the Properties window
Go to the Servers part (which is present below the "Start Action" part )
In the Project URL section, increment the value of Port Number by 1 or 2 (modified Port number must be free) and click
on "Create Virtual Directory"
Save the changes and run the application using CTRL+F5
Hope this helps!

You can use appcmd.exe in C:\program files (x86)\IISExpress
appcmd list vdir should list the virtual directories and
appcmd delete vdir VDIR.NAME to delete. Or, if you use Powershell, the commands start with .\, e.g., .\appcmd list vdir.

VS 2019 -
There are multiple places that the applicationhost.config resides. Two of those should are where the virtual directory data is put.
First location:
C:\Users\YourUserName\Documents\IISExpress\config\applicationhost.config
Second location:
C:\YourPathToSolutionFolder\.vs\SolutionName\config\applicationhost.config.
** please note: in the .vs there are two folders one is the config folder and the other should be the name of your solution. Navigate into your solution named folder and you will find another config folder. Inside there is the applicationhost.config file you need to edit.
In both files you will need to remove the following (I just search for virtualdirectory).
<application path="/virtualDirectoryName" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\projects\Project1" />
</application>
Hopefully you won't have to delete the entire .vs folder which is an option if needed.
Note: This combines two answer from above Diego Murakami and BraveNewMath

Related

How to make Visual Studio Publish honor the "Copy if Newer" setting?

An ASP.NET (not Core) project.
Certain files, such as NLog.config, are set to Copy if newer (as per NLog documentation).
And if I click Build this works: NLog.config is only copied to the build directory if it is newer than the version that already is in the build directory.
However, if I click Publish, then NLog.config is copied to the publish directory no matter what, overwriting the version that is already there. (I'm publishing to file system).
It would be really helpful if the version that already is in the publish directory took precedence.
Note that NLog.config is likely to contain settings that are specific to the environment the app is published to and cannot be set in the app's source code nor pushed to git.
There is an option to make Publish not delete files already present if it can't overwrite them with anything - so if I remove NLog.config from source code and only keep it in the publish (and build) directories, things will work as expected. However, I cannot do so: I was explicitly asked to make Publish place a default version of NLog.config that only logs to a file if there is no such version in the publish location yet.
Is there any remedy here? Is there any way to force Publish not to overwrite NLog.config if it already exists in target location or at least not overwrite it if it's newer?
Maybe you can try and fiddle with CopyToPublishDirectory that can have the values Always, PreserveNewest, Never:
<None Include="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>

Cannot read web.config file Asp.net core web application

I am trying to run some sample code for ASP.NET Core and Angular 2.
I cloned the project from https://github.com/PacktPublishing/ASPdotNET-Core-and-Angular-2 and changed the sdk version in the global.json to the current version I have installed (1.0.0-preview2-1-003177). When I run the web application I get the following error page:
I grepped the project looking for the config file path but came up with nothing. I also contacted support but they aren't helpful.
Does anybody know how to change the config file path?
You must open hidden .vs folder in root of your solution folder, then find applicationhost.config file in the config folder.
... and change
<virtualDirectory path="/" physicalPath="......"
to the proper path.

Where is IIS Express 7.5 wwwroot Directory

Using Windows 7 I have installed the IIS Express 7.5 but I cant find where is the wwwroot directory on my system! There is no "inetpub" folder on my C drive as well.
Can you please let me know where I can put a file like hello.aspx file to be run?
Thanks
By first-hand experience and also by this other SO answer, usually IISExpress holds a directory with its own data files at: C:\Users\<username>\Documents\IISExpress.
There you can find the default directories for each web site log files (Logs\ and TraceLogFiles\) and especially you can find all web sites configurations in file config\applicationhost.config. That one has a <sites> section with a <site> node for each website created.
For each website, its <virtualDirectory> node specifies actual root location in physicalPath attribute:
<site name="YourWebSiteName" id="12345">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\Physical\path\to\your\website\root"/>
</application>
...
</site>
C:\Users\YourUserName\Documents\My Web Sites\web-Site1
One simple way to test is just key in a test file in your site root, e.g.
http://localhost:1714/test.txt
System will throw a 404 error, in the "Detailed Error Information" section, system will show the "physical path" the server is trying to retrive the file.
Usually it is in your home directory. Something like c:\Users\<yourname>\Documents\IISExpress
you will see a location like below path
C:\Users\YOURUSERSNAME\AppData\Local\Temp\Temporary ASP.NET Files
But where is the global directory for IIS Express? Quick answer is
that there is not one. IIS Express is very much directory based.
That being said, the 2 solutions I have been able to work out are:
Add the group of files to your root path of your web site
Create a virtual directory in IIS Express’ applicationHost.config file for the location of your global files
More details

Removing comments from web.config on build

Is it possible to remove the commented lines from a web.config on build?
xml transform is fine to remove some elements but I couldn't find any syntax to clean the comments from the file.
We are using TFS 2010 build server for our builds.
<add xdt:Transform="RemoveAll" xdt:Locator="XPath(//comment())" />
Put this node within the root node of your transform file. "XPath(//comment())" selects all XML comment nodes to delete.
UPDATE: See actual and working answer below.
It's not possible to do with xml transformation.
But you can do it with your own console app or msbuild task.
See example code here Remove XML comments using Visual Studio 2010 Web Config Transformation
I had a similar problem where I wanted to remove dev comments from the config files before I published to the web site. I wrote an app that will recursively remove comments from config files in the directory I specify on the command line. The sample below assumes YourCommentRemover will do the same.
I included the comment remover project as part of my solution and referenced it in the web app I plan to deploy. You can just add the executable as a reference if you want. Since I didn't want the comment remover to get deployed, I added a task to delete it from the bin directory where it was being staged for deploy, (ProjectDir)obj\$(Configuration)\Package\PackageTmp\.
Open your project file in a text editor (You can right-click on the project file in the solution explorer and select 'Edit Project File').
Go to the very end of the project file and insert the following before </Project>:
<Target Name="BeforePublish" BeforeTargets="MSDeployPublish">
<Exec Command="$(ProjectDir)bin\YourCommentRemover $(ProjectDir)obj\$(Configuration)\Package\PackageTmp" />
<Exec Command="del $(ProjectDir)obj\$(Configuration)\Package\PackageTmp\bin\YourCommentRemover.*" />
</Target>
This target will run before any files are copied to the web application location on publish.

Website publish failing due to file path being too long

I am trying to publish a Website project from a vendor that has ridiculously long paths to some of its files. When publishing, the error is:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
When I publish, Visual Studio 2012 Update 3 is attempting to write to a temp directory, and the prefix is quite long:
C:\Users\cuser\AppData\Local\Temp\WebSitePublish\MidasCMS400v9-1580334405\obj\Debug\Package\PackageTmp\
I thought I might be able to redirect VS to a different temporary directory at c:\tem by following this SO answer: Temp path too long when publishing a web site project
I create my publication profile, and as soon as I open it, there is an error indicating that WebPublishMethod is not an element of PropertyGroup. Regardless, I updated the file so it looks like this:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Sites\MidasPublish</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<AspnetCompileMergeIntermediateOutputPath>c:\tem\</AspnetCompileMergeIntermediateOutputPath>
</PropertyGroup>
</Project>
When I try to publish, I get the a modal box pop-up entitled "File Modification Detected", with the message "The project YourWebsite has been modified outside the environment", and it asks me if I want to reload. In my error list, I continue to get the error about the path being too long, as it is not attempting to use the c:\tem directory I identified.
I need to put this bloody thing onto a server, I am up for any solution that allows me to publish the bloody thing. I don't know much about the Website project template, so please let me know if there is a better way.
From http://forums.asp.net/t/1944241.aspx?Website+publish+failing+due+to+file+path+being+too+long
Add the following line in default PropertyGroup of web project file.
<IntermediateOutputPath>..\Temp\</IntermediateOutputPath>
You can likely make the above path C:\temp or ......\Temp (as needed to get it as close to root of the drive as possible.
In my case, there was no .csproj or .vbproj (website project file) but there was a website.publishproj file that warns you not to edit it, but I did anyway, and it did the trick.
Thanks to Stelvio, from http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation , there is a solution :
Well, I found a workaround that ALLOW work with path with more than 260 chars.
Disclaimer: I've tried this trick only on Windows 8 x64 and Visual Studio 2013
So, to make it work I've just create a junction to the folder with the mklink command:
Assume this is the original path: d:\very\very\long\path\to\solution\folder, you can obtain a short link as d:\short_path_to_solution_folder just jaunching this command from a dos shell as administrator:
mklink /J d:\short_path_to_solution_folder d:\very\very\long\path\to\solution\folder
change source and destination path to you needs
Best Regards!
Stelvio
from this link :
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation
While moving the project closer to the root file does work. I found a link to a solution that did work for me. The site also does a great job at discussion the issue as well as the details behind his solution.
Sayed Hashimi's solution to long path issue
EDIT:
To Summarize the provided link:
You can update your publish profile file, which is used by MSBuild, to include a replace rule that will shorten the path of your output when publishing to a web deploy package (Zip file).
For example, let's say publishing using the default profile created by Visual Studio, we get the following paths in the zip file:
archive.xml
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\bin
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\bin\WebApplication1.dll
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\index.html
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\Web.config
parameters.xml
systemInfo.xml
The trick is to replace all of the path defined after Content with a shorter path. In this particular example, replace the path with "website" in the PackagePath element.
One can edit the publishing profile file (.pubxml) and add the follow lines near the end of the file, just before the Project element is terminated.
<PropertyGroup>
<PackagePath Condition=" '$(PackagePath)'=='' ">website</PackagePath>
<EnableAddReplaceToUpdatePacakgePath Condition=" '$(EnableAddReplaceToUpdatePacakgePath)'=='' ">true</EnableAddReplaceToUpdatePacakgePath>
<PackageDependsOn>
$(PackageDependsOn);
AddReplaceRuleForAppPath;
</PackageDependsOn>
</PropertyGroup>
<Target Name="AddReplaceRuleForAppPath" Condition=" '$(EnableAddReplaceToUpdatePacakgePath)'=='true' ">
<PropertyGroup>
<_PkgPathFull>$([System.IO.Path]::GetFullPath($(WPPAllFilesInSingleFolder)))</_PkgPathFull>
</PropertyGroup>
<!-- escape the text into a regex -->
<EscapeTextForRegularExpressions Text="$(_PkgPathFull)">
<Output TaskParameter="Result" PropertyName="_PkgPathRegex" />
</EscapeTextForRegularExpressions>
<!-- add the replace rule to update the path -->
<ItemGroup>
<MsDeployReplaceRules Include="replaceFullPath">
<Match>$(_PkgPathRegex)</Match>
<Replace>$(PackagePath)</Replace>
</MsDeployReplaceRules>
</ItemGroup>
</Target>
Now, the publish profile paths should look something like the following:
archive.xml
Content\website
Content\website\bin
Content\website\bin\WebApplication1.dll
Content\website\index.html
Content\website\Web.config
parameters.xml
systemInfo.xml
The answer of Jason Beck worked to me with a small change. To avoid the error "The IntermediateOutputPath must end with a trailing slash." use the "\" at the end of the path:
..\Temp\
Your "CONFIG_PUBLISH_FILE.pubxml" should look like this (The "..." omits other configuration that you file may have):
...
...
..\Temp\
...
At the time of publishing the project, the visual studio compiler checks the size of the files that are part of the project.
So I searched for long names in files.
I found and renamed those files.
Did Work perfectly
In my case it was because the default legacy string length limitation of windows. This was still set to 256-character limit.
To fix this, from an admin powershell session I ran the following command
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
I needed to reboot the system for the changes to take effect.
Microsoft reference document link here
This error comes because of long path name....U just cut your folder from current location to D drive or F drive. suppose your project folder name is "myproject", and you should cut this folder and paste to D drive of F drive,that your current path name will be D:\myproject or F:\myproject. Then you publish again......It will work...

Resources