In IIS under the site I can create a virtual directory which has a different phisical path.
Can I somehow do the same in ASP.NET MVC project? Something like adding a directory which links to a different directory.
The problem is I have some folder outside the site which contains images. I added that folder in IIS under site as Dropbox, which points to completely different location:
Now I also use such paths in the app with Server.MapPath:
"~/Dropbox/Dev/Product/Images"
This all works when I publish in IIS. But how can I do the same locally debugging? Is there a way to add virtual directory to my project in Visual Studio?
I am assuming that your are running your website using IIS Express. You can find your website IIS Express configuration file by right clicking the IIS Express tray icon and then show all applications. Select your website and then click on the config path as shown in screenshot
In config file, find your website site element and then you can add new virtualDirectory element like this:
<site name="Website1" id="2">
<application path="/" applicationPool="website1">
<virtualDirectory path="/" physicalPath="D:\Projects/Website1" />
<virtualDirectory path="/Images" physicalPath="C:/Images" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54558:localhost" />
/bindings>
</site>
Here you can see Images virtual directory is added.
Related
I need to have WebAPI project working under different base path than usual. I created simple project under Visual Studio that uses WebAPI and ASP.NET 5.
Under base path set to http://localhost:38170/ my project works fine and I'm able to get values from test controller (http://localhost:38170/api/values).
At this stage my IIS Express configuration is:
<site name="WebApi" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:38170:localhost" />
</bindings>
</site>
I tried changing App URL under project properties to reflect my need:
http://localhost:38170/xxx
Now running project and hitting http://localhost:38170/xxx/api/values results in 404. Trying http://localhost:38170/api/values returns values from controller just as if nothing changed. I noticed that changes in Visual Studio are not reflected in IIS Express configuration (I don't know if they should be...) in any way.
I tried changing path on IISExpress manually like in this thread: Creating virtual directories in IIS express.
<site name="WebApi" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/xxx" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:38170:localhost" />
</bindings>
</site>
The results are:
http://localhost:38170/api/values - 500.19 Error (config error) and that is fairly ok - I don't plan this to work
http://localhost:38170/xxx/api/values - 502.3 - Bad Gateway on hitting httpPlatformHandler
I suppose that error is somewhere in httpPlatformHandler configuration but I'm not sure how to do it in conjuction with IIS Express. My web.config is:
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
</system.webServer>
</configuration>
I tried random changes like changes in path attribute to xxx/* but nothing works.
EDIT:
To clarify the question.
How to setup WebAPI on ASP.NET 5 (ASP.NET Core) on IISExpress using httpPlatformHandler and Kestrel to set base path other than root.
You corrupt the file as your modification does my honor the IIS Express configuration rules.
I will suggest you use a smart tool such as Jexus Manager to manipulate it, and then you can sync the Visual Studio project with the correct URL.
For example, the 404 is expected, as your application tag has path set to /, so there is no application nor virtual directory to serve xxx.
The 500.19 later is also expected, as while adding a valid virtual directory named xxx, you deleted the root virtual directory. That's totally wrong as a root virtual directory must present.
I've created a test website to make use of the warm-up module provided by the Application Initialization Module.
I've used ScottGu's Blog as well as Wade Hilmo's Blog.
I've installed the module and implemented the changes to the applicationHost.config file and restarted the server:
<applicationPools>
<add name="MySite" autoStart="true" startMode="AlwaysRunning" managedRuntimeVersion="v4.0" />
</applicationPools>
<sites>
<site name="MySite" id="4" serverAutoStart="true">
<application path="/" applicationPool="MySite" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\MySite" />
</application>
</site>
</sites>
Once the server restarts, I check Task Manager and my site's not running. So then deleted the changes and used AppCmd to do it from the Command Prompt:
%windir%\System32\inetsrv\appcmd set apppool "MySite" /autoStart:true
%windir%\System32\inetsrv\appcmd set apppool "MySite" /startMode:AlwaysRunning
%windir%\System32\inetsrv\appcmd set app "MySite/" /preloadEnabled:true
%windir%\System32\inetsrv\appcmd stop apppool "MySite"
%windir%\System32\inetsrv\appcmd start apppool "MySite"
And Bobs your uncle it works perfectly. I then restarted the server for good measure and checked the applicationHost.config file again and the changes I've made are not there; yet the site is running fine in Task Manager and if I access the site it's available immediately. Stopping and starting the app pool sees the site immediately pop up in Task Manager.
So my question is, where are the settings being stored if not in the applicationHost.config file?!
Edit: I've done a lot of digging and playing but am no closer to an answer. Firstly, after some searching I found out there's another applicationHost.config file. The one I've been editing sits in
%windir%\System32\inetsrv\config\applicationHost.config
The second is apparently something to do with 32bit but the first applicationHost.config clearly shows the 32bit web sites. Even so, the second one didn't reflect my changes either
%windir%\SysWOW64\inetsrv\config\applicationHost.config
I did a search for applicationHost.config it found a few other copies of it but seems more like those are initial / backup copies of them.
I then created a second website, the two sites are now configured as such:
<applicationPools>
<add name="MySite" autoStart="true" startMode="AlwaysRunning" managedRuntimeVersion="v4.0" />
<add name="MySite2" autoStart="true" startMode="OnDemand" managedRuntimeVersion="v4.0" />
</applicationPools>
<sites>
<site name="MySite" id="1" serverAutoStart="true">
<application path="/" applicationPool="MySite" preloadEnabled="true">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\MySite" />
</application>
</site>
<site name="MySite2" id="2" serverAutoStart="true">
<application path="/" applicationPool="MySite" preloadEnabled="false">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\MySite" />
</application>
</site>
</sites>
First site should autostart and second site should be on demand.
I then ran the following AppCmd commands:
%windir%\System32\inetsrv\appcmd set apppool "MySite" /startMode:OnDemand
%windir%\System32\inetsrv\appcmd set app "MySite/" /preloadEnabled:false
%windir%\System32\inetsrv\appcmd set apppool "MySite2" /startMode:AlwaysRunning
%windir%\System32\inetsrv\appcmd set app "MySite2/" /preloadEnabled:true
to configure them the opposite way round to how they're configured in the applicationHost.config. I Restarted the server completely and checked the config, it's still as I originally left it and not reflecting the changes and neither site is starting.
I then changed the config of site 2 to autostart (as for site 1) and restarted the server but it still didn't start. I then ran:
%windir%\System32\inetsrv\appcmd set apppool "MySite2" /startMode:AlwaysRunning
%windir%\System32\inetsrv\appcmd set app "MySite2/" /preloadEnabled:true
%windir%\System32\inetsrv\appcmd stop apppool "MySite2"
%windir%\System32\inetsrv\appcmd start apppool "MySite2"
and it started, restarted server and it started up, though site 1 is still not starting on startup. So I ran:
%windir%\System32\inetsrv\appcmd set apppool "MySite" /startMode:AlwaysRunning
%windir%\System32\inetsrv\appcmd set app "MySite/" /preloadEnabled:true
and restarted the entire server again just for good measure and both sites are starting.
Are you using notepad++ to make these changes and to view the file? If so, use standard notepad that comes with Windows (or notepad2 if you've replaced notepad with notepad2). I guess notepad++ writes only to the 32 bit one by default (according to http://forums.iis.net/t/1151982.aspx?Opening+applicationHost+config+in+anything+other+than+Notepad).
I have added multiple sites inside a azure web role, like below:
<WebRole name="site1" vmsize="Small">
<Sites>
<Site name="site1" physicalDirectory="..\site1">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" hostHeader="www.site1.nl" />
</Bindings>
</Site>
<Site name="site2" physicalDirectory="..\site2">
<Bindings>
<Binding name="ndpoint1" endpointName="Endpoint1" hostHeader="www.site2.nl" />
</Bindings>
</Site>
</Sites>
......
I have added two configurations for each web application to make database connection string different -> Web.Dev.Config and Web.Staging.Config.
When i right click the Cloud Service projcet -> 'Publish', and choose the 'Build configuration' to 'Dev', these two web site were be published successful.
But in the site2, the connection string inside Web.config seems incorrect , the folder of site2 contains all configurations of web.config files like Web.Dev.config and Web.Staging.config, and all cs files still exists, it seems the site2 was not build correctly.
Is there anybody has experience about this?
I have the same issue, but I've found a few other articles that explain how to resolve this.
https://kellyhpdx.wordpress.com/2012/04/11/deploying-multiple-web-applications-to-a-single-azure-instance-and-applying-web-config-transforms-correctly/
Windows Azure with Multiple Sites in One Role not transforming 2nd web.debug.config to web.config
I recently moved my "My Documents" folder from the C: to the D: drive. This seems to have broken my ability to debug web app in Visual Studio. I'm assuming that visual studio creates entries like the following in applicationhost.config, and I am wondering where the first physicalPath for the root virtualDirectory comes from, as I am fairly certain that is the problem (I've pretty much confirmed that VS creates an entry like the following when a solution is opened):
<site name="My.Application-Site" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\myname\Documents\My Web Sites\My.Application-Site" />
</application>
<application path="/My" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\repos\MyCheckout\My\My.Application" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:49924:localhost" />
</bindings>
</site>
When I try to run the app in debugger, the browser pops up with an error, the relevant bits of which are below. Notice the path to web.config still uses C:, even though it seems to know the right place for tracelogfiles:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Config Error Cannot read configuration file
Config File \\?\C:\Users\myname\Documents\My Web Sites\My.Application-Site(2)\web.config
Requested URL http://localhost:50616/My/
Request Tracing Directory D:\users\myname\My Documents\IISExpress\TraceLogFiles\
So the question is where in Visual Studio (or IIS) is the path for the web.config file determined, and how do I change it. And/or is there some other reason or insight anyone can provide as to why I am getting this 500.19 error?
Another recent change (other than moving My Documents) is I uninstalled a trial of VS Ultimate 2013 and installed VS Pro 2013 -- could that have somehow caused this? Both of changes have been made between the time I was last able to debug the app normally and getting this error.
For someone looking for an answer to "where in Visual Studio (or IIS) is the path for the web.config file determined, and how do I change it" or "I moved my application from its origin folder"
Right-click in Project Properties > Web Tab and Create Virtual Directory buttom.
It all happened when I was developing (and debuging, of course) my application on two different machines, with different paths (and Drives) to the source code managed by git.
Hope it helps
I have a really frustrating problem. I have a website in ASP.NET. I use IIS Express for development. I recently moved my project files and folders from a usb drive to my dropbox folder to avoid carrying the drive around.
After moving my project to the dropbox folder, I got this error that IIS cannot read my config file. I noticed the path was pointing to my usb drive. So I copied my web.config to the path displayed in the error message and it worked again, if I delete it again, the error comes again.
So I think that somewhere in my project there is a config setting that points to my usb drive, although it should point to my local dropbox folder.
I have attached a screenshot of the error:
Translation:
Module IIS Web Core
Message Unknown
Handler still undetermined
Error code 0x80070003
Config error The config file cannot be read
Config file .........
Requested URL ...........
Physical path
Authentication method still unknown
Authenticated user still unknown
Debug path ..................
I had this problem when trying to launch a service from a project created on another machine that was saved in DropBox.
In the project folder there is a file in PROJECTFOLDERNAME/.vs/config/applicationhost.config
In that file is a list of sites in XML like so:
<sites>
<site name="WebSite2" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\WRONGPATH\Dropbox\Website2\src\Website2" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:64655:localhost" />
</bindings>
</site>
<site name="WebSite4" id="3">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\Nick\Dropbox\Website3\src\Website3" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:64655:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
Change the virtualDirectory physicalPath to the correct path. The problem I still face is I work on this project from two different locations, I don't really want to change this back and forth all the time.
Uhh, I have looked for the answer for more than 2 hours. I tried cleaning up every bin, .vs folders. But those did not help me.
Eventually, I fixed the issue by re-showing (re-binding) the path to the project in IIS Manager
I had this issue when I moved my "My Documents" folder to another location. IIS Express was still pointing to old path. The only way I could fix this is by doing clean installation of IIS Express.
Uninstall IIS Express
Remove the 'IIS Express' folder that contains configuration file.
Install IIS Express