Disable Visual Studio Web Server Directory Browsing - cassini

I'm using Visual Studio's built in web server to test and EPiServer applicaiton. When I have the app running in IIS, if I hit the root of the virtual directory, EPiServer will take over and server the defaul page to me. Using the Visual Studion server (which I am doing for license reasons with the SDK), it always gives me the 'Directory Listing' view of my site. Does anyone know how to configure this web server to not allow the directory listing/browsing?
Additional Information:
This problme only seems to effect the root of the visual studion web server (i'll call it cassini from here on in). As an example, if I run a site from localhost:6666, then what I will find is that localhost:6666/en/ will work just fine and the EPiServer VPP will know what it is doing. If I use localhost:6666/, then the VPP never kicks in (or so it seams). It seems to me that when the root of cassini is hit, it checks to see if the page exists (which it does not as I have no default). If it decides that the page does not exist, then it serves up the directory listing, rather than 404. The first thing to do for me is to dispable directory browsing in cassini, then look at why the VPP is not being actioned correctly.
So I suppose the base of the question is: Is there a way to modify these settins in Cassini when it is Visual Studio starting everything off?
(EPiServer may be a red herring, but just in case, it's CMS version 5)
Further Update
I managed to get hold of the source for Cassini 3.5 and gave that a whirl. 3.5 works just fine and behaves like IIS in this instance. I.e. the lack of default document does not lead to a Directory listing, rather if allows the HTTP handlers to kick in and then EPiServer does the rest! So the question is, can I achieve the same in Visual Studios effort at a web server?

Make sure you have a ~/Default.aspx file. It won't render, but it's needed in cassini for the virtual path providers to get a chance to handle the request for '/'.
Of course, if you make it anyway you might as well use it for the start page :-)

Even if you could get the server to not show the directory listing, could you get EPiServer to take over?
EDIT: From comments
The fact that it works with /en/ makes me think this is something that Microsoft could fix. I suggest you ask the vendor if they have a workaround. If they do not, then please create a suggestion at http://connect.microsoft.com/visualstudio/. Be sure to specify details about EPIServer, URL to the vendor, etc.
Be clear that it works with /en, but you want a setting permitting it to work at the root.
Once you create the suggestion, please edit your question to include the link to the suggestion you create. That way, others reading your question can vote on how important they think this is.

The EpiServer part confuses me. However, if you are asking how to set the default page for the VS development server (based on the Cassini code), you're expected to do that in the project properties (right click on web project), Web, Start Action, Specific Page, foo.aspx.
I suspect the cassini/VS development server doesn't have a default page feature-- the source code for the cassini server (the ancestor of the VS development server) is on the web and you can check that and add a default page by building a custom version. And it doesn't have a very long list of other features that IIS has.

Which EPiServer version are you running?
Did you install it using EPiServer Manager?
There has always been some differences in the configuration between running the site at the root of a host name or as a (virtual) directory.
Check the site settings block in web.config and make sure you have a default.aspx at the project root.

Related

Windows Server 2019: IIS 10: HTTP Error 403.14 - Forbidden: The Web server is configured to not list the contents of this directory

All,
I am migrating a working .Net Framework Website from IIS 8.5 on a Microsoft Windows Server 2012 to IIS 10 on a Microsoft Windows Server 2019.
The new web site is showing the error
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
As far as I can see the website on the new server is configured the same as on the existing.
Neither have directory Browsing enabled nor a default file set as is recommended by most of the posts which exist discussing this error.
I have run the following which is also recommended.
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
The problem still exists.
I came across a post saying there might be an issue if paths referenced in the web.config are not correct but they look fine.
Has anyone got any insight into what else might cause this issue?
Are there any differences between IIS 8.5 and IIS 10 or between windows servers 2012 and 2019 which might cause this issue?
Thanks
This problem occurs because the website doesn't have the Directory Browsing feature enabled. Also, the default document isn't configured. To resolve this problem, use one of the following methods:
Method 1: Enable the Directory Browsing feature in IIS
To resolve this problem, follow these steps:
Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
In the Features view, double-click Directory Browsing.
In the Actions pane, select Enable.
Method 2: Add a default document
To resolve this problem, follow these steps:
Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
In the Features view, double-click Default Document.
In the Actions pane, select Enable.
In the File Name box, type the name of the default document, and then select OK.
More information you can refer to this link: HTTP Error 403.14 - Forbidden when you open an IIS webpage.
All those clowns glibly posting that "HTTP Error 403.14 - Forbidden: The Web server is configured to not list the contents of this directory" can be fixed by configuring the web site by either enabling the Directory Browsing feature or adding a default document are really not understanding what they are talking about. Anyone can copy a solution from one post and paste to another.
I'm not going to pretend I know what I am talking about but I have fixed my issue and will share what I did here to see in the hope it helps others.
I created a project (of the same type as the application I was trying to deploy) using my IDE (MSVS) in the same .Net version of the application I was trying to deploy. In this case it was creation of an MVC project in .Net Framework 4.5.
I did nothing to it. All I wanted was a skeleton.
I replaced all the files in the home directory of the web site I had an issue with, with the files of this skeleton project.
I attempted to browse to the web site and it worked successfully. Note the directory browsing was not enabled nor was a default directory set.
This proved to me that those settings were irrelevant.
Having googled around, some sites point to paths in config files causing an issue if they do not exist, eg a logging path to d:\logs where that directory was missing. It didn't fix my issue but there's no harm checking.
I stumbled across a post which talked about the roles and features enabled on the server. In Web Server (IIS)/Web Server/Application Development they had selected "Application Initialisation" and "ASP".
The Windows Sever 2012 server I was moving the application from, where it work without a hitch, did not have those selected so had not selected them on the Windows Server 2019 I was moving them to when I set that server up.
It made no sense that this would be the solution but having tried everything else I activated those two options.
Stone me if the issue was resolved.
As a check I removed those two options and the problem came back and when I reselected them it went away again.
This struck me as pretty conclusive only having thought I'd found the cause of the problem I built the website from scratch and the problem came back again.
It took a number of iterations but eventually I got there, more by luck than judgement and whatever the cause was it was due to an issue in the application which wasn't being logged in event viewer so focus on permissions to files being written to: not only that the app pool account is set up on the directories it needs access to but also that it has modify or even full control.
All those muppets robotically posting advice on configuring the web site by either enabling the Directory Browsing feature or adding a default document will no doubt copy this and paste it into their posts to claim the credit but c'est la vie.
I hope this post is of use to someone, apart from those muppets.

How to debug an ASPNET Core application in a subfolder

I have a ASPNET Core application that works fine on my machine with URL https://localhost:5001/, but not on the client's server, where the application's URL is https://example.com/subfolder/.
The problem seems to be an error in a redirect on one of the pages, where a user is sent to /something rather than /subfolder/something. I'm using relative URL's only. In the rest of the application, redirects work fine.
I was wondering if it is possible to debug the application in Visual Studio and have it run in a subfolder, preferably using Kestrel, but IIS Express might be an option too.
Update after comments While adding specifics about the problem, I found out that I was looking at it from the wrong angle. The actual problem seems to be that the application is started as https://example.com/subfolder (no trailing slash). Redirecting to ./something (or just something) will result in https://example.com/something.
(My real question therefore would be: If https://example.com/subfolder is opened, how can I redirect to https://example.com/subfolder/? I'll first try to fix this myself, maybe it should be configured in the webserver. In the meantime, I'd still like to know if subfolders can be used in debugging)
In development, it seems you can't debug your program in subfolder.
I don't recommand you to spend a lot of time to serach how to do that, and I also suggest you use IIS. Because in IIS, it supports Virtual Application, and I think it is you want.
Steps:
create a main website, and create a virtual application.
choose the project folder as Physical Path, mainsite and virtualapplication.
open vs2019 as administrator, maybe you need open it twice,and one for main site and another for virtual application.
then you can attach to a running process on your local machine.
you can start your two webapp in one port, and you can debug them.

URL Routes In IIS7 MVC 5 (Single Paged Application)

After publishing a MVC5 web application of mine to my IIS server (Individual User Accounts), it would seem that the URL is accessed incorrectly.
During debug, it would be e.g http://localhost:1234/api/Account/UserInfo?=XXXXX
The debug works just fine. The only issue kicks in after I've published it via my IIS7 server.
After publishing and using Google Chrome's console, it would appear that the page is requesting for a resource at mydomainname.com/api/Account/UserInfo?=XXXX instead of mydomainname.com/WEBAPPLICATIONNAME/api/Account/UserInfo?=XXXX.
My best guess is to modify the URLs in /Scripts/app/app.datamodel.js but it would just cause more parsing problems.
I've searched around and can't seem to find any related problems. I hope someone here will be able to lend a hand.
Look like you are using relative path like "/api/Account/UserInfo". Instead i'll recommend you to use #Url.Content("/api/Account/UserInfo"). This will solve your problem
Explanation
In local system when we run application in WebDev server it never have sub folder (like WEBAPPLICATIONNAME) therefore you relative path work correctly. but when you host your application in IIS under Default website in another new website /Virtual folder (like 'WEBAPPLICATIONNAME') then "/api/Account/UserInfo" fall back to Default Website because for '/' in starting. #Url.Content or #Url.Action make sure to add virtual directory name, hence changing your path to "/WEBAPPLICATIONNAME/api/Account/UserInfo" in IIS.

Best practices for deploying an MVC application on IIS7

I'm not a web admin, and I'm new to IIS. So, I'm looking for advice.
My MVC application (e.g. fooapp) is the default application for my site (e.g. foo.bar). I used IIS Manager to add the site to IIS7. When I import the application, IIS Manager wants to put it in it's own directory (/foo), and tells me I shouldn't put it in the base (site) directory. This means that to get to my default MVC view, I have to enter the URL http://foo.bar/fooapp/. Needless to say, I want to get there via http://foo.bar/
I see 2 possible solutions:
Add a default page to the site directory that redirects to the MVC app.
Ignore the IIS admonition and load the app into the site directory.
My IIS7 knowledge is limited. I have played around with some options (such as HTTP Redirect). Since nothing changed, I obviously don't understand what I'm doing.
Anyway, if there are some considered "best practices" and/or other suggestions, please let me know.
Tbh, I'm not sure why the IIS manager is trying to convince you to add it as a sub app.. Maybe you just didn't do it right >_>
I've got a couple servers running with IIS7/7.5 and they have apps running in the root of the website.. No problem there :)
You might want to create a new website in IIS (right click on websites, choose "Add Web Site"), point the "Physical Path" directly to the folder your website's stored in, and set the Host name to whatever host you use (foo.bar ? :) )
This should work just fine )
In terms of deployment, if you use VS2010 I'd really recomment looking at Web Deploy.. It's a new addon written for IIS7, and allows one-click publish to IIS directly from VS2010. I'm using it on my site and it works flawlessly :)
Check out Scott Hansellman's talk about it, or check it out in the IIS website

Deploying MVC Application to Web Server doesn't run correctly

I have reading posts all night looking for an answer to my issue and haven't found anything that works for me yet. I am sure there is a simple way to do this but I haven't been able to discover it yet.
Details:
MVC 2 Preview
Asp.net 3.5 sp1 framework
VS 2008 C# web application
Windows Server 2008
IIS 7
I have the application running well through VS 2008 no problem. When I hit the play to run in debug mode it starts the ASP.NET Development Server the application loads fine and works as expected, great!
When I publish the application locally or to my web server both on IIS 7 the application doesn't run correctly. Some of the icons are missing and the google maps map is missing. When I view the source it appears correct at first glance, but I can see the paths to the images are looking for the MVC paths and it isn't finding them. It appears the app is running as a regular asp.net app and not an mvc app, maybe?
I also tried to just hit the full source code locally on localhost and the exact same issue is present.
So, I guess my question is how do I deploy a MVC application to run the same in IIS as it does through the development server.
PS The environments are clean and pretty much out of the box.
#user68137 is correct in saying that you need to use relative paths for the images.
I got caught out on this one too, and here's my previous SO question about it...
In short, you need to do something like this...
<img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" />
Hope this helps!
I had the relative paths set, but what I didn't realize is when I deployed it to the server it went to wwwroot\subsite... I had the relative paths set to src="....\image.jpg" to get back to the root of the site. My error was that if the site is not in the root then the subsite drills back to the root to find the images and of course doesn't find them. Same thing was happening with the JS files. I used the Url.Content and it worked great! problem solved!
The interesting this is when running through the VS dev server with a subsite it still worked well and found the paths even though it shouldn't have. VS dev server <> IIS
Thanks for your help on this!
Simon.
Once you know the virtual path to the location you are deploying the project to, you should go into the project configuration in Visual Studio and add it to your project. This way the visual studio development server will use the same path structure as the deployment server. This will save you countless hours of work when deploying.
When you run your website through Visual Studio, every single request gets processed through the ASP.NET pipeline, including images, CSS and other resources. IIS by default only processes specific extensions (e.g., aspx) unless you tell it otherwise through configuration. Paths like '/content/images/yourimage.jpg' should work just fine...I suspect it's something amiss in your IIS configuration.
Another possibility which I've run into is any custom ISAPI filters you may have installed on the IIS server (e.g., ISAPI_rewrite). It's easy to set up rules in its configuration that lead to some very unexpected results.

Resources