Asp.Net httphandler cause 500 (Internal server error) - asp.net

I want to add a handler to my existing web form application.
Following this walkthrough in web.config I've added:
<configuration>
<system.web>
<httpHandlers>
<add verb="post" path="redirect.ashx" type="RedirectHandler"/>
</httpHandlers>
</system.web>
</configuration>
I've created a Generic Handler (called RedirectHandler.ashx) in App_Code folder,
but when I run the application (VS2017) it causes a 500.
The tutorial makes a distinction between registering in IIS 6.0 and IIS 7.0. I'm not sure which one applies to me considering that VS runs IIS Express 10.0. Anyway, I've already tried both with poor results.
I'm a noobie to web forms but it seems pretty straightforward. I don't understand why it doesn't work.
EDIT: Creating a new project and adding httphandlers doesn't cause any issue. So it must be some configuration with my current project but I have no idea what may cause the error.
EDIT 2: To answer at the 500 error, the problem was caused by the wrong "type" in httpHandlers. Type should be "Namespace.class".
This post really helped me to figure out a few things.

Related

One IIS site, Two applications with different .NET versions

I porting an old site into MVC 4 and I have it working so far. However there is also a third party forum which we use which isn't changing. In IIS 7 I created a new Application for the forum and it also has its own app pool (MVC is .NET4 and forum is .NET 2).
The applications are in different physical directories on the server, and here's what the IIS directory structure looks like with ForumApp being the sub-application:
\RootMVCSite\
\RootMVCSite\bin
\RootMVCSite\[OTHERMVCFILESANDFOLDERS]
\RootMVCSite\web.config
\RootMVCSite\ForumApp\
\RootMVCSite\ForumApp\bin
\RootMVCSite\ForumApp\[OTHERFORUMAPPFILESANDFOLDERS]
\RootMVCSite\ForumApp\web.config
However, when I go to the forum I get the following error:
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Line 20: <system.web>
Line 21: <compilation targetFramework="4.0" />
The confusing part is that it is looking in the web.config for the root MVC site rather than the forum site where the sub-application is pointing. What do I need to do in IIS or web.config to fix this? Is there a way to prevent the sub-app from looking at the root site's web.config?
I figured it out. By wrapping the offending configuration sections with the location tag, those settings would be ignored by any child applications.
<location path="." inheritInChildApplications="false">
<system.web>
<compilation targetFramework="4.0" />
</system.web>
...
</location>
If there's anything I should be wary of regarding this solution, please chime in and suggest any improvements or advice!
Check the application pool for that site in IIS and make sure it targets .NET Framework 4.0. By default a new application pool will be set to .NET 2.0.

Troubleshooting Silverlight 5 and Ria services [Web-Services-AuthenticationService.svc does not exist]

I have two different versions of a Silverlight 5 project using Ria services. Both work locally. The older version (A) works when deployed to ISS7. The new version (B) does not. There is user/password authentication that fails for version B with the error:
Load operation failed for query 'Login'. the remote server returned an error: NotFound.
Referencing various SO and MSDN posts over the past week, I have tried many troubleshooting techniques. Adding error logging as suggested here to the web.config results in the following being logged:
The service '/ClientBin/MyApp-Web-Services-AuthenticationService.svc' does not exist.
Researching that led to finding this forum post which suggests creating a dummy .svc file with the name/path it is looking for. The result:
The service '/ClientBin/DBCRM-Web-Services-AuthenticationService.svc' cannot be activated due to an exception during compilation. The exception message is: The ending bracket '>' for the 'ServiceHost' directive is missing in the '.svc' file..
The details of the above error aren't largely important as it was a blank .svc file I supplied. It merely served to confirm that fact that the project was indeed dependent on it
Here's the kicker... the working version DOES NOT contain this file either, yet it does not throw an exception.
Searching for any reference to needing the service surprisingly turned up a result in both solutions. Both MyApp.Web.g.csfiles are identical (ran a CSDiff) and both contain the line:
public AuthenticationContext() :
this(new WebDomainClient<IAuthenticationServiceContract>(new Uri("DBCRM-Web-Services-AuthenticationService.svc", UriKind.Relative)))
{
}
Both have the same package/deploy settings. I am deploying to a file system, then copying the files over to IIS on my host server.
Questions:
Where is a setting that makes this .svc file a requirement? It's clearly not needed in version A, but is in version B. Again, file MyApp.Web.g.csis the only reference to it, and it exists in both versions.
MyApp.Web.g.cs is a generated file. What service in Visual Studio 2010 creates this file? Also, can I modify it to not include the call to the .svc file in question?
I'm going to start merging the two solutions together to see at which point the .svc file becomes neccessary. Any ideas in the meantime would be greatly appreciated!
WCF Ria Services registers an HttpModule in order to manage the wcf ria services calls. When the request arrive to the server that module read the url and understand which service to instantiate and which method to call. So it's absolutely normal that you don't find any .svc file
Don't mess with the .g.cs your problem isn't here.
Take a look at your web.config file, you should find rows like this
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
...
</system.web>
and this
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
...
</system.webServer>
Besides making sure that the "DomainServiceModule" entries are present in Web.Config as stated above, another thing is that RIA requires ASP .NET compatibility mode to be enabled. Here is a link to Microsoft's deployment guide for RIA:
http://msdn.microsoft.com/en-us/library/ff426912(v=vs.91).aspx
In the third paragraph of the "Configure the Web Server" section, it states that you need the following in your Web.Config file:
<system.serviceModel>
...
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
...
</system.serviceModel>
When this is missing, you get the behavior described in your question.
Before you do any of this make sure the regular bin folder is actually deployed containing your actual code.
I was deploying with MSDEPLOY to a new server and it did not deploy bin folder. You're not going to get anywhere without that!

HTTP Handler doesn't hitted, while it run over cloud, when request needs to be redirected to another Server from IIS?

My Asp.net application is hosted over Azure Cloud,
In that application I do have a Java Chat control, which has its server on Linux,
now I have created a HTTPHandler to redirect that chat request to the Linux server, but some how it doesn't work over the Cloud environment (though it works very well on web environment)
it shows the below error
Microsoft Visual Studio
Windows Azure Tools for Microsoft Visual Studio
There was an error attaching the debugger to the IIS worker process for URL 'http://127.255.0.0:82/' for role instance 'deployment16(315).Cloud.AnotherHttpHandler_IN_0'. Unable to start debugging on the web server. See help for common configuration errors. Running the web page outside of the debugger may provide further information.
Make sure the server is operating correctly. Verify there are no syntax errors in web.config by doing a Debug.Start Without Debugging. You may also want to refer to the ASP.NET and ATL Server debugging topic in the online documentation.
I have even put the Handler under System.webServer as well in the web.config file, see below code
<system.web>
<httpHandlers>
<add verb="*" path="http-bind/*"
type="HelloWorldHandler"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add verb="*" path="http-bind/*" name="HelloWorldHandler" type="HelloWorldHandler"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
I don't know what restricts it over the cloud environment.
Please take a look at this question to see how to configure httpHandlers for running in Azure.
Most importantly - remove the httpHandlers section under the system.web and leave only handlers under system.webServer. Then add also the resourceType="Unspecified" attribute to the handler declaration. This should solve your issue.
I too had same problem.
I fixed it in following way .
The Problem was my machine is 32 bit and the azure server is 64 bit.
In Order to solve the problem i only changed Enable 32 bit option in
the advance setting of application pool. And the Original code worked
out fine.
i got this help from this Link

How to get TinyMVC .NET class Library to work on ASP.NET MVC 2?

I am trying to implement the TinyMCE Spellcheck plugin that uses GoogleSpell. The thing is I am trying to install it in an MVC environment.
I started by referencing the .NET class Library DLL (MoxieCode.TinyMCE) in my project.
Then, I added this code to my web.config:
<system.webServer>
<handlers>
<add name="TinyMCE" verb="GET,HEAD,POST" path="TinyMCE.ashx" type="Moxiecode.TinyMCE.Web.HttpHandler,Moxiecode.TinyMCE" />
</handlers>
<!--previously existing rules-->
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I then added these lines to my tinyMCE.init({}); call:
plugins: "spellchecker",
theme_advanced_buttons3: "spellchecker",
spellchecker_languages : "English=en",
spellchecker_rpc_url : "TinyMCE.ashx?module=SpellChecker",
These steps are outlined in the tutorial here. I then followed instructions from this stack overflow post which recommended the following modification to global.asax to make it mvc friendly:
routes.IgnoreRoute("TinyMCE.ashx");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Everything seems fine accept that when I browse to /TinyMCE.ashx i get this error:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /TinyMCE.ashx
Why can't asp.net mvc process that url?
Make sure the handler is being applied at the correct element in the web.config.
IIS supports 2 types of modes, an integrated mode and a classic mode.
The classic mode is the how versions previous to IIS 7 worked. Depending on that, you put the handlers in the web.config section that applies to asp.net, or in the section that is picked by IIS directly.
After a fair bit of frustration I stopped messing with it on localhost in VS 2010. I suspected that it was a problem relating to IIS configuration, so I uploaded the site to a sub-domain of the live server. It worked without any problem.
I'm not sure why the code didn't work on localhost but evidently, the steps I followed to execute TinyMCE .NET and GoogleSpell were correct because they work on the live server.

HttpModule URL rewriting using IIS6 with no extensionless URLs

We are using the Intelligencia URLRewriting module for asp.net with version 2.0 of the framework and IIS6. Our URLs typically have no extension.
I understand that IIS6 cannot really deal with this situation without a blanket wildcard (which causes other problems).
However, it works! Sometimes. At other times (e.g. on one dev's machine, and on my machine when I point a different virtual directory at the app) it doesn't. By "it doesn't work" I mean the configured HttpModules never even get hit.
Can anyone explain this?
Thanks.
So it turns out what was happening was the following:
request comes in to (say) http://website/products/productid
IIS can't find this hence we get a 404
by chance we have a custom error page set up in IIS for 404s
this error page sticks the referring URL on the end of the 404 error.aspx page
so we get a redirect coming into asp.net along the lines of:
http://website/error.aspx?404;http://website/products/productid
our URLRewriting regexes were now set up in such a way that they discarded the error.aspx bit and dealt with http://website/products/productid as if it were the actual URL
so asp.net renders http://website/product.aspx?id=productid as requested!
I guess this could prove to be a useful kludge for someone, but we're moving to an isapi filter. One heads-up is that this will by default lead to a tight loop of redirects!
If you run a site using the Visual Studio development web server all requests will be handled by asp.net so your HttpModule will run.
On IIS6 this should not happen unless it is set up to forward the requests to asp.net.
Are you sure that when "it works" you aren't running under the Cassini development web server included in VS.NET ? Because extensionless wildcards do work under Cassini, which can be very confusing to say the least.
If you are using an IIS6 with ASP.net 4.0, you must specify and register the modules like this:
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
not
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</modules>

Resources