RPC not working if application is located in a virtual directory

109 views
Skip to first unread message

Alexey Solonets

unread,
Mar 21, 2012, 6:54:31 AM3/21/12
to extdirec...@googlegroups.com
So the problem is in the subject. Everything is fine while the application is launched in the VS Development Server (with Virtual path = "/"). But when I change either Virtual path or run the application under IIS 7 with Virtual directory, /rpc URL becomes unavailable (404 - Not found).

Steps to reproduce the problem:
1. Create new empty MVC 2 Application - "Mvc2Application"
2. In the Package Manager Console type:
Install-Package ExtDirectHandler
3. Go to the project's Properties - Web, check "Use Local IIS Web server" and click "Create Virtual Directory". You should have the "http://localhost/Mvc2Application" URL.
4. Open Web.config file and add the following lines to the "system.web" section:
<httpHandlers>
    <add verb="*" path="/rpc" type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />
</httpHandlers>
5. Open Global.asax.cs file and add the following line to the RegisterRoutes function:
routes.IgnoreRoute("rpc/{*pathInfo}");
6. Create HomeController and the corresponding Home view
7. Open created view and add the following line inside the <head> tag:
<script type="text/javascript" src="rpc"> </script>
8. Compile and run the application.

Using WebKit's developer tools or Firebug you can see that " http://localhost/Mvc2Application/rpc" address wasn't handled (404).
Any solution for applications located in virtual directories?..
Thanks.

Gian Marco Gherardi

unread,
Mar 21, 2012, 7:01:08 AM3/21/12
to extdirec...@googlegroups.com
I think this is related to how ASP.NET define handlers. try replacing

<add verb="*" path="/rpc" type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />

with

<add verb="*" path="rpc" type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />

Note that "/rpc" has been changed to just "rpc"

Gian Marco Gherardi
http://gianmarco.gherardi.me

Alexey Solonets

unread,
Mar 21, 2012, 7:09:48 AM3/21/12
to extdirec...@googlegroups.com
I've tried :) Tried with /rpc, rpc, Mvc2Application/rpc, /Mvc2Application/rpc, *rpc* and so on. Nothing helps. 
Yeah, I thing you are right about ASP.NET. Now I'm googling for related topics. Maybe I can find a solution there.


On Wednesday, March 21, 2012 5:01:08 PM UTC+6, Gian Marco Gherardi wrote:
I think this is related to how ASP.NET define handlers. try replacing

<add verb="*" path="/rpc" type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />

with

<add verb="*" path="rpc" type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />

Note that "/rpc" has been changed to just "rpc"

Gian Marco Gherardi
http://gianmarco.gherardi.me


Gian Marco Gherardi

unread,
Mar 21, 2012, 7:14:20 AM3/21/12
to extdirec...@googlegroups.com

Iis 7 changed the way handlers are defined in web.config in a way that is incompatible with what visualstudio dev server require.

Try searching on google how to define handlers in iis7+

GMG (sent from mobile)

Alexey Solonets

unread,
Mar 21, 2012, 7:42:46 AM3/21/12
to extdirec...@googlegroups.com
Finally! :)

The solution:
1. Create class:
public class DirectRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        return new ExtDirectHandler.DirectHttpHandler();
    }
}

2. Add following to the RegisterRoutes function in Global.asax.cs:
routes.Add(new Route("rpc/{*pathInfo}", new DirectRouteHandler()));

3. No <httpHandlers> and routes.IgnoreRoute("rpc/{*pathInfo}") are required anymore.

Evviva!

Gian Marco Gherardi

unread,
Mar 22, 2012, 4:09:43 AM3/22/12
to extdirec...@googlegroups.com
Thanks for sharing!

I've updated wiki page at  https://github.com/gimmi/extdirecthandler/wiki/MvcIntegration 

Gian Marco Gherardi
http://gianmarco.gherardi.me


Brian

unread,
May 11, 2012, 4:14:08 PM5/11/12
to ExtDirectHandler
In .NET 4.0, you need to use the following:

<system.webServer>
<handlers>
<add name="DirectHandler" verb="*" path="rpc"
type="ExtDirectHandler.DirectHttpHandler, ExtDirectHandler" />
</handlers>

for an IIS Virtual Directory.

The following does NOT work in .NET 4.0

Edit Web.config and add the following line under <configuration>
<system.web> <httpHandlers>

<add verb="*" path="rpc" type="ExtDirectHandler.DirectHttpHandler,
ExtDirectHandler" />

as described:

https://github.com/gimmi/extdirecthandler/wiki/Gettingstarted

On Mar 22, 1:09 am, Gian Marco Gherardi <gianmarco.ghera...@gmail.com>
wrote:
> Thanks for sharing!
>
> I've updated wiki page athttps://github.com/gimmi/extdirecthandler/wiki/MvcIntegration
>
> Gian Marco Gherardihttp://gianmarco.gherardi.me
>
> On Wed, Mar 21, 2012 at 12:42 PM, Alexey Solonets <alexey.solon...@gmail.com

Gian Marco Gherardi

unread,
May 12, 2012, 2:39:11 AM5/12/12
to extdirec...@googlegroups.com
I think this is more because of IIS6 vs IIS7 than .NET3.5 vs .NET4

anyway tank you for reporting the issue, i will update the Wiki

Gian Marco Gherardi
http://gianmarco.gherardi.me


Gian Marco Gherardi

unread,
May 12, 2012, 2:48:32 AM5/12/12
to extdirec...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages