开发者

Method continues executing after return statement

开发者 https://www.devze.com 2023-03-10 09:39 出处:网络
I am currently trying to solve a strange bug in an IIS url rewriting provider I have written. I have an if ... else with a return statement inside each block. What happens is the first block (if) is h

I am currently trying to solve a strange bug in an IIS url rewriting provider I have written. I have an if ... else with a return statement inside each block. What happens is the first block (if) is hit and executes normally, the return is hit but then the method doesn't return and continues into the else block. Here is the offending code:

public string Rewrite(string value)
{
    string v = value;
    if (v.Contains(".aspx") || v.Contains("buzz") || v.Contains("promo")) {
        return v;
    } else {
        string val = "";
        using (DataContext db = new DataContext(cs)) {
            var lp = db.LandingPages.FirstOrDefault(l => l.L_Url == v);
            if (lp != null) val = "landing_page.aspx?id=" + lp.L_ID;
        }
        return CoalesceStrings(val, v);
    } 
}

(I know a lot of that could be done much better, things like the v = value were for debugging purposes - ill improve it when it works properly!)

Any ideas? This doesn't seem like the correct behaviour for this method. I am debugging it in IIS 7.5 using attach to process from VS2010 on a windows 7 x64 machine.

Edited to add: the match pattern in iis is ^(?!(c开发者_开发问答ommon|ajax|Scripts|uploads|xml))(\w|\d|-|.|[?&=/])+


I would guess that you are seeing strange debugging behavior due to different threads running. Are you sure it's the same request that ends up in the else block? IIS is going to handle multiple requests at the same time, some for images, scripts, css, etc. Not just the page itself. If you set two break points in the method, one on the first return, and the other inside the else, it is very possible that after leaving the method from the return statement, the process blocks again on a request to a different resource inside the else statement.

Pay close attention to the thread that is being debugged using the Threads window while debugging. Also watch the value that is coming in, it's probably different.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号