Azure ASP.NET MVC Web.Config Deployment Issue - asp.net-mvc

We are developing an ASP.NET MVC web app that will be hosted on Windows Azure. We have deployed the application a few times during development without any problems. It was actually quite surprising how smooth the process went. Then, when we went to deploy the app for beta testing we kept getting 403 Access Denied errors whenever we tried to navigate to the base url of the site. If we tried to navigate to any of the various Controllers and Actions of the site thereafter we would get 404 The resource could not be found errors.
The other strange thing that we noticed is that we had defined the authentication redirect page to be /Access/SignIn rather than the default Account/Login. Everything worked fine on the development machine and we were redirected to /Access/SignIn but when publishing to Azure we saw we were being redirected to /Account/Login. This made us think there was an issue with the web.config file.
We enabled remote desktop on the Azure deployment and took a look at the web.config file only to find out that it was almost completely empty! The only setting in there was the machineKey. We manually copied the web.config from one of our development machines up to the Azure virtual machine instance and everything started to work from there on.
What in the world would make the deployment wipe out the web.config file? And how can we prevent this from happening as we aren't going to be able to update the web.config file manually every time we deploy an update?

I often solve these sorts of problems by looking at the contents of the .cspkg file. This allows me to avoid waiting for the Azure package upload and initialization. Here are the steps to view the .cspkg contents:
Navigate to the /bin//app.publish folder
Rename the .cspkg file to .cspkg.zip.
Open .cspkg.zip. You will find a .cssx file (which is really a zip file) for each project referenced by the Azure project.
Extract the .cssx file you wich to inspect and rename it to .cssx.zip
Open the .cssx.zip and look around. For WorkerRoles, check out the approot folder. For WebRoles, check out the sitesroot folder.

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.

How to precompile MVC for intranet?

VS2013 Update3, .Net 4.5, MVC, IIS 7
I created a new mvc project.
Tested from VS and it works.
From IIs, I created a folder in wwwroot, and made it an application. Add app pool with .net 4.0. Enabled windows authentication and disabled Anonymous authentication. Set service account in app pool and webapp.
From VS I deploy to IIS with default settings (which is NOT precompile) (using File System)
Site works fine on IIS.
But…
If deploy with the precompile setting clicked on. Web site fails with 403 error. Tried various combinations and get never get the precompiled to work. Always works when non-precompiled.
ASP.NET 4 was is registered in IIS.
Tried modules runAllManagedModulesForAllRequests="true" with no success.
I'm out of ideas and looking for help
Server Error in Application "xxx/MVCHELLOWORLD"
Internet Information Services 7.5
Error Summary
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Detailed Error Information
Module
DirectoryListingModule
Notification
ExecuteRequestHandler
Handler
StaticFile
Error Code
0x00000000
Requested URL
http://xxx/MvcHelloWorld/
Physical Path
C:\inetpub\wwwroot\MvcHelloWorld\
Logon Method
Negotiate
Most likely causes: •A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
Things you can try: •If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
• Enable directory browsing using IIS Manager. 1.Open IIS Manager.
2.In the Features view, double-click Directory Browsing.
3.On the Directory Browsing page, in the Actions pane, click Enable.
•Verify that the configuration/system.webServer/directoryBrowse#enabled attribute is set to true in the site or application configuration file.
Links and More InformationThis error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.
View more information »
I just had the same issue and have been trying to resolve it for the last couple of days.
I have a Windows 8 pc running IIS 8 Express.
I copied an MVC site that was compiled and published from another pc, ran it, and got the same 403.14 forbidden as above. I then tried publishing the site uncompiled and running it and the site loaded just fine.
I then decided to load Visual Web Express on the Windows 8 pc and created a dummy MVC site and ran it compiled and uncompiled and it worked just fine. This showed me that IIS 8 Express was configured and working properly and there must be some issue in the way the site was compiling.
I tried different precompile methods during the publish including do not merge, merge all and merge each folder but none of those many any difference.
In the end I solved this by changing the Copy Local property to true for every Assembly referenced within the project. Even all the default ones that should be referenced from the GAC.
Not sure if I needed to copy every assembly to the bin folder or not but given the large number of assemblies referenced within my project this seemed easier then trying them 1 by 1.
EDIT: Made some changes and republished the site and now I'm back to the 403.14 forbidden again :(
I'm really pulling my hair out on this one as to why it isn't working.

What do I need to do to get MVC to work on IIS7? Does not show page, just shows directory

I've just file system deployed an intranet site to one of our internal servers. The site is configured with it's own application pool w/.net 4. The site is configured to allow anonymous access. The NetworkServices account has read access to the directory/s. For trouble shooting purposes I have directory listing enabled.
When I hit the site I get the directory listing, why does the home/index page not come up as expected? Other servers that I have deployed to have just worked. I can not seem to find a difference here.
Also I have the site configured to come up as http: //myip:8081/
I've already run aspnet_regiis -I and checked to make sure the pool was the correct version.
I rolled back my .Net version from 4.5.1 to 4 and reinstalled all the nugget packages.
I have copied local all the DLLs just to be sure.
The original project was targeted to .Net 4.5 and I had down-converted to 4. I thought I had changed all references and configuration items but I must have missed something.
I created a new project targeting .Net 4 and copied my code files into the new project.
Compiled and deployed and all worked correctly.
Not sure what item in the web.config wasn't changed (or maybe something else in the project) but this worked and was fairly quick.

Deploying ASP MVC 5 App with IIS 7.5

I try to deploy ASP MVC 5 app in virtual directory (without creating new iis application)
I use IIS 7.5
I already put
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
in web.config file.
But when i go to app url with IE browser it shows me just directory listing like in screenshot below
Is there a way to deploy MVC 5 in virtual directory and make it work like usual MVC application?
You need to convert the virtual directory to application. Right click on it in the IIS management console and choose Convert To Application.... Also make sure that the associated application is configured to use Integrated Pipeline Mode.
I solved this problem earlier in my production environment by checking the directory pointer in IIS. Apparently when I unzipped the deployed site from one server to the next, the zip utility made an extra level, so IIS was pointing to /MyProject when the files were in /MyProject/MyProject. I had a little better clue though, you have Document Browsing enabled based on that screen shot, make sure not to do that in production. I set the site to log custom errors and got a 403.14 response, from there found a blog on my mistake. You need to setup the environment to find the specific module that's failing, I think something to do with trace routes, idk. I'm a software developer that always gets forced into doing devOps; was googling my own problem and thought I'd throw you a line. Without a specific error message, all I can tell you is IIS is not connecting to .NET; something is not configured correctly. Turn off directory browsing, google how to get good error logs back, and let us know the status code so we can help you: 403.14, 401, 500, 404? Also give us the module that's failing. If it's the last one on the handler list, guess what, IIS isn't connecting to the app, which I suspect is your case.

Resources