简体   繁体   English

asp.net中的自定义httphandler无法获取请求查询字符串?

[英]custom httphandler in asp.net cannot get request querystring?

I've been trying to get this to work. 我一直试图让这个工作。 It's basically a way to have certain MVC pages work within a webforms cms (umbraco) 这基本上是让某些MVC页面在webforms cms(umbraco)中工作的一种方法

Someone tried it before me and had issues with MVC2.0 (see here) , I have read the post, did what was announced there, but with or without that code, I seem to get stuck on a different matter. 有人在我之前尝试过它,并遇到了MVC2.0的问题(请参阅此处) ,我已经阅读了帖子,做了在那里宣布的事情,但是无论有没有该代码,我似乎都陷入了另一件事。

It seems like, if I call an url, it fires the handler, but fails to request the querystring passed, the variable originalPath is always empty, for example I call this url: http://localhost:8080/mvc.ashx?mvcRoute=/home/RSVPForm the handler is supposed to get the mvcRoute but it is always empty. 似乎,如果我调用一个url,它将触发处理程序,但无法请求传递的查询字符串,变量originalPath始终为空,例如,我将此URL称为: http:// localhost:8080 / mvc.ashx?mvcRoute = / home / RSVPForm处理程序应该获取mvcRoute,但始终为空。 Thus gets rewritten to a simple / and then returns resource cannot be found error. 从而将其重写为简单的/,然后返回找不到资源的错误。

Here is the code I use now: 这是我现在使用的代码:

public void ProcessRequest(HttpContext httpContext)
{
        string originalPath = httpContext.Request.Path;
        string newPath = httpContext.Request.QueryString["mvcRoute"];
        if (string.IsNullOrEmpty(newPath))
            newPath = "/";

        HttpContext.Current.RewritePath(newPath, false);
        IHttpHandler ih = (IHttpHandler)new MvcHttpHandler();
        ih.ProcessRequest(httpContext);
        HttpContext.Current.RewritePath(originalPath, false);
}

I would like some new input on this as I'm staring myself blind on such a simple issue, while I thought I would have more problems with mvc itself. 我想对此提出一些新的建议,因为我对这样一个简单的问题视而不见,而我认为mvc本身会有更多的问题。

have no time to investigate, but after copying the site over to different locations, using numerous web.config changes (unrelated to this error but was figuring other things out) this error seems to have solved itself. 没有时间进行调查,但是在将站点复制到其他位置之后,使用了许多web.config更改(与该错误无关,但是正在弄清楚其他事情),该错误似乎已经解决了。 so its no longer an issue, however i have no clue as to what exactly made this to work again. 所以它不再是一个问题,但是我不知道到底是什么使它再次起作用。

on a side note 在旁注

ih.ProcessRequest(httpContext);

should have been, 本来应该,

ih.ProcessRequest(HttpContext.Current);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM