Anders
Anders

Reputation: 12560

How come this redirect does not work with this section of code?

foreach (string oName in oValues)
{
    if (string.IsNullOrEmpty(Request.Form[oName]))
    {
        oCount += 1;
    }
}
if (oCount == 0)
{
    _clientID = Request.Form["ClientID"];
    _password = Request.Form["Password"];
    _pracType = Request.Form["PracType"];
    _encrypt = Request.Form["Encrypt"];

    if (GetCRC(_clientID) == _password)
    {
        if (_clientID != null)
        {
            var verify = VerifyClientInformation(int.Parse(_clientID));
            var gsa = new GSDataLayer.Authentication.Auth();

            gsa.CreateAuthEntry(_clientID, _password, _pracType, _encrypt, verify.CanUpdate);
            _aMgr.GotoHomePage();
        }
        else
        {
            error.Text = "This conditional failed.";
        }
    }
    else
    {
        _aMgr.GotoErrorPage("nocrc"); 
    }

}
else
{
    _aMgr.GotoErrorPage("noform");  
}

the GotoErrorPage method:

public void GotoErrorPage(string errorcode)
{
    if (HttpContext.Current.Request.UserHostAddress != "127.0.0.1") // for testing only
    {
        var instance = new Control();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Redirect(instance.ResolveClientUrl(
                     string.Format("~/ErrorPage.aspx?e={0}", errorcode)));
        HttpContext.Current.Response.End();
    }
}

If oCount is 0, it redirects just fine but if it is > 0 the redirect does not happen. Any ideas on why this might be?

thanks

edit

Well, I feel rather silly...the conditional for the UserHostAddress in GotoErrorPage() was the culprit. I had forgotten that this was remnant from my initial testing because I did not want any redirects to happen, just outputting text (errors, results, etc). After removing that conditional, redirects happen just fine.

What is throwing me for a spin, though, is it was working fine earlier. Although, I think I also figured that out as well. Since I am developing this on a network, some of my colleagues can access it via the intranet by using my computer's name (program003) instead of localhost. I think before the 'problem' showed up, I was using my computer's name instead of localhost while testing. Regardless, when I use localhost, the IP is 127.0.0.1, but when I use program003 I get this IPv6 address:

fe80::b1d7:b18b:d10f:f526%8

If I am not mistaken, the loopback address for IPv6 is supposed to be ::1? Very strange.

Upvotes: 0

Views: 179

Answers (3)

Anders
Anders

Reputation: 12560

See my edit for problem/solution.

Upvotes: 0

annakata
annakata

Reputation: 75834

Looking at the logic if GetCRC(_clientID) == _password is true and _clientID != null is false, then you're left with no action taken at all, so you have at least one possible explanation there.

May I also take the opportunity to say how much the dropped braces and hungarian breaks my mind? This is very hard to read for my eyes.

Upvotes: 1

Sev
Sev

Reputation: 15707

Where is "errorcode" defined in your GotoErrorPage() method? Does it accept a parameter?

Upvotes: 0

Related Questions