C# MVC: Cannot Debug in IIS Express - c#

I just changed my laptop. I am moving my old project done in MVC 4 and was done in Visual Studio 2012. My current Visual Studio in my new laptop is 2017 version.
There is a problem when I want to debug my MVC application. This error comes out after I run the debug:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
Most likely causes: A default document is not configured for the
requested URL, and directory browsing is not enabled on the server.
I never set my application to be listed in directory browser. My application is an MVC application which will run global.asax and redirect to my home page.
How can I fix this?

enable directory browsing.
keep this into your web config file then rename the add value="pagename.aspx"
<system.webServer>
<defaultDocument>
<files>
<add value="yourpage.aspx" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
</system.webServer>
or
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
You can also enable directory browsing from IIS
Open a command prompt, and then go to the IIS Express folder on your computer. For example, go to the following folder in a command prompt: C:\Program Files\IIS Express
Type the following command, and then press Enter:
appcmd set config /section:system.webServer/directoryBrowse /enabled:true

Got the same error, but MVC5 on VS2017. Eventually found I got the error because i had marked Application_Start() in Global.asax as a static. I did that because i made the mistake of following this Code Analysis recommendation:

This is a potential duplicate of
HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents
Different context since you are trying to debug in IIS express and you are not hosting the application in IIS, however the error is the same and the answers is worth checking out. Could set you on the right path.
Would have commented but don't have enough rep yet.

Make sure you have defined your default application inside the hosts file in your new laptop.
This is a cause for many headache.
See it under:
C:/Windows/System32/Drivers/etc/hosts

Related

Deployed web on Azure cannot access a .less file (error code 404). Local IIS deployment works without error

I deployed a website in https://pokegotool.azurewebsites.net.
However, when I use a browser to access it and read the browser console, it told that the "Content/pre-css/styles.less" file is inaccessible (error code 404).
I build the web site locally in IIS and it had no such problem as the file is loaded successfully. I am sure that the file exists in Azure deployment place.
This URL is ZIP archived project: https://www.mediafire.com/file/i6745pz5j43cw2z/RangeGen.zip/file
Feel free to use it.
Is this an error from Azure or from my project itself? How could I fix it?
I have deployed your project and met the same issue . Basically , it is due to that Azure app service IIS server have not mapped correct MIME type for .less files by default.
To solve this issue , just adding a map record in your web.config file as below :
<system.webServer>
<staticContent>
<mimeMap fileExtension=".less" mimeType="text/plain" />
</staticContent>
</system.webServer>
It works on my app service , try it here : https://rangegen20190902101335.azurewebsites.net/Content/pre-css/styles.less
Pls mark me if it solves your issue : )

HTTP Error 403.14 - Forbidden with Debug of ASP.NET Web Application

I'm trying to start ASP.NET Web Application
but I got this error with debug:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
Module
   DirectoryListingModule
Notification
   ExecuteRequestHandler
Handler
   StaticFile
Error Code
   0x00000000
Not sure if it exactly what I have to do, but as it shown, I must follow this instruction but when I'm trying to open IIS Manager on Windows 10, it says that the Windows cannot find 'inetmgr'.or 'inetmgr.exe'
So not sure what I have to do to figure out with this error.
Since it doesn't seem like you have the full IIS installed, try adding this into your web.config that lies within the directory you want to browse:
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
...at least so you can get past this problem. If you're doing this for debugging, fine, but you have to seriously consider whether this is really what you want to allow on a production server.

How to publish MVC application with form authentication on IIS

I have an ASP.NET MVC application using Form Authentication, with the following configuration in the web.config file:
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
I can successfully publish the application on IIS from within the Visual Studio. But when I browse it in the browser, I get a 500 Internal Server Error with the following description:
Check if your IIS components like ASP.NET 4.6, etc are installed. Sometimes this problem occurs in the lake of IIS main components.
You can check this in "Turn Windows features on or off"
Give your virtual directory root folder all rights (read/write)
make sure the app pool is using the right version of the .net. it is by default pointing to .net 2.0.
Here we go:
Did you register .NET with IIS? If not run the following commands:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
You need to do this from an elevated command prompt (cmd) (...run as admin)
Than you have to create this row in your config file:
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
Follow this tutorial: enter link description here
Hope it helps;)
The error message is telling you that this section is locked, generally in the applicationHost.config file. So you need to unlock it before you can modify it in the web.config file. See this for more info. Optionally run this command to unlock the section.
%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/modules
I would avoid reinstalling .Net and changing permissions until you have tried this.

Asp.net core rc2 binary can not run IIS 8.5 window server 2012, getting error 502.3

I am trying to get my new asp.net core rc2 version running on my dev server that running IIs 8.5 and window 2012 server
I've followed the steps list in here, which is:
On my local:
Create a new asp.net core project using VS 2015 (Dev14) U2
Change the web.config stdoutLogEnabled="true", create a new deploy profile and publish it locally to a folder
Make sure the website works on IIS Express.
On my server
Installed the DotNetCore.1.0.0.RC2-WindowsHosting.exe and reset IIS
Setup new app pool with no managed code, setup new website in IIS that points to the local: D:\apps\myapp1\
Copy the deploy content to D:\apps\myapp1\ (such as the dll is D:\apps\myapp1\myapp1.dll)
dotnet.exe is on the path. I can even go to D:\apps\myapp1\ and dotnet myapp1.dll. It will bring up the nano server.
What I see when I hit http://mydevserver/myapp1 (or localhost/myapp1 on my dev server):
HTTP Error 502.3 - Bad Gateway
When I view the Event log, I can see a bunch of failure like this:
my logs folder on D:\apps\myapp1\logs is also empty. There is no log in that folder whatsoever.
At this point I am pretty lost on what to do. Help!!!
Here's the content of my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
</xml>
There are a few things you can do to troubleshoot:
go to the published app and try running it without IIS
logs won't be written if the folder does not exist and by default the logs folder does not exist
if it is a portable app make sure the path to dotnet.exe is on the system wide %PATH% (note you need to do iisreset after you set it to make IIS pick it up)
I wrote a blog post explaining how ASP.NET Core apps work with IIS and the post contains the section on troubleshooting your very problem.
So I finally figured out what's wrong. Apparently because I did not setup my website under "Default Web Site" of IIS, so IIS (I think) routes my website incorrectly. My fix is to move my website under Default Web Site.
One of my friends found another way to setup the website outside of Default Web Site by disabling the Default Web Site. I have not tried to get both Default Web Site enable and MyApp website enable working. Maybe somebody else can contribute in...

debugging a HTTP Handler

I am using IIS 6 on 2003. I have created a HTTP handler dll that inherits from IHttpAsyncHandler. The dll builds into the inetpub\www8080root\common\bin directory. It is meant to intercept all requests.
The web site is set to monitor port 8080. I have created a common folder in the www8080root directory and have created a virtual directory in II6 to point to it.
I created a web.config file in the common directory
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" defaultLanguage="c#" />
<httpHandlers>
<add verb="*" path="*"
type="x2Handler.x2Handler, x2Handler" />
</httpHandlers>
</system.web>
</configuration>
When I access http://localhost:8080/common/index.html the HTTP handler causes a crash of w3wp.exe, when I look in the event logs I can see the error within the handler that caused the crash. When I set a breakpoint within VS 2005 the code it doesn't get hit.
In order to debug I need to somehow attach to the process when it is running under IIS but as soon as it processes a request, it crashes.
How do I debug a HTTP Handler dll under IIS? I can't see a aspnet_wp.exe process to attach to as described here: C#, Debugging an HTTPHandler
EDIT:
By adding Debugger.Break() I now receive the message "w3wp.exe has triggered a breakpoint" and it allows me to select a debug environment, but it loads without symbols
No symbols are loaded for any call stack frame. The source code cannot be displayed.
I set Tools->Options->Debugging->Enable Just My Code
I set the path to the common/bin location to load symbols from. Any manually set breakpoints still display:
The breakpoint will not currently be hit. No symbols have been loaded for this document.
EDIT:
When it loads it appears to be looking for the symbols of ntdll.pdb. Even if I manually load the symbol file for the httpHandler it makes no difference.
The code is definitely executing though.
Add Debugger.Break() a few lines before the exception occurs. This should give you a popup asking to attach a debugger.
The problem was that .Net had been installed prior to the version IIS. I had noticed the "Edit configuration" button was disabled and found this site http://www.warfiblog.com/edit-configuration-disabled.
Following the instructions:
You will need to go to Start -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt. On the prompt write down this command:
aspnet_regiis -r
The above command will register dot net with IIS and now the button will also be enabled.
In doing that it fixed the debugging issue!

Categories

Resources