How to publish MVC application with form authentication on IIS - c#

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.

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 : )

C# MVC: Cannot Debug in IIS Express

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

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...

Server Error in '/' Application.Runtime Error

<httpRuntime executionTimeout="600" maxRequestLength="11000"
requestLengthDiskThreshold="80"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true" enable="true"
shutdownTimeout="90" delayNotificationTimeout="5"
waitChangeNotification="0" maxWaitChangeNotification="0"
enableHeaderChecking="true" sendCacheControlHeader="true"
apartmentThreading="false"/>
<trust level="Full"/>
<customErrors mode="on" defaultRedirect="~/Contents/error.aspx">
</customErrors>
This is my error handling in web.config which is not working.
If there is any exception thrown it doesn't redirect to /Contents/error.aspx page
Is it because I set /Contents/error.aspx -
If not what's wrong with the error handling.
Have you configured the virtual directory as an ASP.NET application for the right framework version?
This error can be caused by a virtual
directory not being configured as an
application in IIS.
In IIS, you can have several applications, but they must be configured as an application. Generally, when you create a web project it maps directly to an IIS application.
Check with your hosting service on how to create an IIS application for your web app.
See IIS Setup
Take a look at here
Try using two '/' in the directory:
//Contents//error.aspx
Hope this helps :)
set customErrors mode="Off" in the web.config to see the actual error. As suggested by Sachin. It turned out to be a compilation Error I had to fix and could enable customErrors again.

Parse error with Generic Handler using IIS

What made me curious is that the generic handler works just fine when I'm running the Web App in a Visual Studio ASP.NET Development Server. When I change the config to run it directly from IIS the handler just dies.
It's an image handler, it writes back an array of bytes to be rendered in an Image object. As I said, it works fine in VS Development Server, but fails on IIS. It doesn't even get called...
The error I get when I'm trying to call it directly is this:
Parser Error Description: An error occurred during the parsing of a
resource required to service this request. Please review the following
specific parse error details and modify your source file
appropriately. Parser Error Message: Could not create type
'YourImageHandler'. Source Error: Line 1: <%# WebHandler
Language="C#" CodeBehind="YourImagehandler.ashx.cs"
Class="YourImageHandler" %>
Handler on web.config:
<system.web>
<httpHandlers>
<add verb="*" path="*.ashx" type="YourImageHandler"/>
</httpHandlers>
</system.web>
The Generic Handler is in the same assembly of the Web Project, and the whole thing is running on IIS 7.
If you are using IIS 7 in pipeline mode then the handler definition must be in <System.webServer>
Like this:
<system.webServer>
<handlers>
<add name="YourImageHandlerName" path="*.ashx" verb="*" type="YourImageHandler" />
</handlers>
</system.webServer>
Check here: http://blogs.msdn.com/b/tmarq/archive/2007/08/30/iis-7-0-asp-net-pipelines-modules-handlers-and-preconditions.aspx
IIS 7.0 has two pipeline modes: integrated and classic. The latter is
sometimes referred to as ISAPI mode.
Integrated mode allows both managed and native modules to register for
events in the IIS pipeline. This enables many new scenarios, such as
applying ASP.NET forms authentication to non-asp.net requests (static
files, classic ASP files, etc).
Classic mode is identical to IIS 6.0. In classic mode, the ASP.NET
pipeline (BeginRequest, AuthenticateRequest,…, EndRequest) runs
entirely within the IIS pipeline’s EXECUTE_REQUEST_HANDLER event.
Think of ASP.NET in classic mode as a pipeline within a pipeline.
The other option is to run your site in "classic" mode, in classic mode IIS 7 works like IIS 6 and has the same behaviour (for what matters here) as your Cassini web server.
Hope that help.
You have to add preCondition attribute in web.config file
<add name="HandlerName" verb="*" path="Handlers/HandlerName.ashx" type="Namespace/HandlerClassName, MyAssembly, Version=1.0.*, Culture=neutral" preCondition="classicMode,runtimeVersionv4.6.1"/>
Its working for my error now.
I think you should add a managed handler mapping to IIS. it is not enough to add config. You can look here .

Categories

Resources