Parse error with Generic Handler using IIS - c#

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 .

Related

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

Why is my application returning the IIS 404 page on my dev environment but not test or production?

OK, so I develop my application locally at http://dev.myapplication.com (using hosts file for the DNS), and then I have http://test.myapplication.com and http://www.myapplication.com.
In IIS 7 (same version, dev test and live), I've opened 'Error Pages' and edited the 404 status code to go to path '/en/404.mvc'. This works locally and I can navigate to http://dev.myapplication.com/non-existent-url.mvc which produces the 404 page.
However, if I navigate to http://dev.myapplication.com/non-existent-url (ie a static address) it shows the IIS 404 page and says it was handled by the static file handler rather than my mvc file handler.
I'm baffled as to why this happens, as it has successfully modified my web.config which in turn allows it to work on test and live, just not locally. i.e. http://www.myapplication.com/404 will show my customized 404 page
You need a wildcard mapping to run all requests through aspnet_isapi - this article explains it nicely: http://www.asp.net/mvc/tutorials/older-versions/deployment/using-asp-net-mvc-with-different-versions-of-iis-cs
Also, check your web.Config has these settings:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

launching a web service (.asmx) in a IIS 6.0

I have developed a web service with the .asmx extension using C# and i want to deploy this into my VPS which has Windows Server 2003 with IIS 6.
Service is running with Framework 4.0 and it's installed in the VPS also. When I upload the precompiled version into the VPS it shows a runtime error
Server Error in '/' Application.
Runtime Error
Description: An application error
occurred on the server. The current
custom error settings for this
application prevent the details of the
application error from being viewed
remotely (for security reasons). It
could, however, be viewed by browsers
running on the local server machine.
Details: To enable the details of this
specific error message to be viewable
on remote machines, please create a
<customErrors> tag within a
"web.config" configuration file
located in the root directory of the
current web application. This
tag should then have
its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are
seeing can be replaced by a custom
error page by modifying the
"defaultRedirect" attribute of the
application's <customErrors>
configuration tag to point to a custom
error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
can anyone help me on this?
Update
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to >service this request. Please review the specific error details below and modify your >configuration file appropriately.
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names >are case-sensitive.
Source Error:
Line 26:
Line 27:
Line 28:
Line 29:
Line 30: Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Source File: C:\Inetpub\vhosts\akashvahini.com\httpdocs\web.config
Line: 28
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET >Version:2.0.50727.3053
this is the new error message after enabling debugging in the web.config
You should enable debugging to diagnose the problem.
Microsoft has a very detailed explanation on how to enable detailed debugging over here.
Server Error in '/' Application.
That error is too generic, check the output after you enabled debugging and post the results.
And don't forget to disable debugging after your site goes live.
Update:
Seems to be permission related:
http://forums.iis.net/p/1042369/1454379.aspx
The ASPNET user account needs permissions for the folder that contains your asmx service.
Update2:
You can give the ASPNET user permissions using the file system permission dialog:
http://www.asp.net/learn/whitepapers/denied-access-to-iis-directories
Might look different on newer versions of Windows.
From my experience "Server Application Unavailable" means that you have got web sites that use different versions of .net in the same application pool.
the site that hosts your webservice needs to be in an app pool that only has .net 4.0 web sites. The application pool is configured on the Home Directory tab in the web site properties.
Looks to me like the application pool is trying to run two difference versions on .net.
Make a new application pool and call it something like .Net4 and then move the new site across to use this app pool and everything should work.
This error is shown by
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET >Version:2.0.50727.3053
Where the site with a .asmx should say .Microsoft .NET Framework Version:4.0 etc...

How to solve a "HTTP Error 404.3 - Not Found" error?

Simple problem. I start up VS2008 and create a new WCF Service application. This will create a default application with a few test methods showing it works. I press CTRL+F5 and it does indeed work! Great! However, it uses the Visual Studio Development server, which I don't want to support.
So I go to the project properties, switch to using a local IIS Web server, create the virtual directory and press CTRL+F5 again. And this "HTTP Error 404.3 - Not Found" error is greeting me back.
So something in my IIS7/Vista-64 setup is wrong. What could I be missing?
Click Start -> Run cmd and type:
cd "\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation"
ServiceModelReg.exe -i
If you faced this problem for the first time. with Windows 8 and IIS 8.0 make sure to activate Windows Communication Foundation HTTP windows feature.
Go to Control Panel select "Programs and features"
From the lift hand side menu select "Turn Windows features on or off".
Expand ".Net Framework 3.5 (includes .NET 2.0 and 3.0)" item
Finally select "Windows Communication Foundation HTTP Activation"
Enjoy your WCF Servcie.
The problem, however, is then to re-register ASP.Net to IIS, which is explained below.
And also if you're on a 64bit machine always use Framework64 paths: C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -iru
Below is the explanation from Microsoft:
http://download.microsoft.com/download/0/A/E/0AEB3BC1-506E-4954-8AB1-4FA2EE75985C/ReleaseNotes.docx
When attempting to run a service that receives messages over the HTTP transport, you may receive an error similar to the following:
Server Error in '/WCFApplication' Application
Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Description: An unhandled exception occurred during the execution of the current Web request. Review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
This error can occur when IIS is installed after installing .NET Framework 4, or if the 3.0 version of the WCF Http Activation module is installed after installing IIS and .NET Framework 4.
To resolve this problem, you must use the ASP.NET IIS Registration Tool (Aspnet_regiis.exe,) to register the correct version of ASP.NET. This can be accomplished by using the –iru parameters when running aspnet_regiis.exe as follows:
aspnet_regiis.exe -iru
And credit, where it's due: Source
I had to tick "HTTP Activation" in "Add Role Services" within Windows Server 2012.
try to install IIS by expanding your Internet information service and then check ASP.Net 3.5 or ASP.Net 4.5 and ISAPI.... in root of world wide.........
please look image to more help
I tried running ServiceModelReg and aspnet_regiis.exe with various flags and added HTTP Activation feature but it still didn't work. What finally worked was adding the following handler manually to my web.config file.
<system.webServer>
<handlers>
<add name="svc-Integrated" path="*.svc" verb="GET,HEAD,POST,DEBUG" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />
My project was running .Net 3.5 and IIS was 7.5 and 7.0.

Categories

Resources