문제

I have inhereted an application Asp.net C# application that I need to deploy. It was written 18 months ago by a contractor and never deployed till now. The code behind file on our login page has this bit of code:

            //if for some reason javascript is not enabled, redirect back to login page
        sb.AppendLine( "<head><meta http-equiv=\"refresh\" content=\"30;URL=./?logout=1\"><link rel=\"Stylesheet\" href=\"./Styles/Main.css\" type=\"text/css\" /></head>" );
        sb.AppendLine( "<body onload=\"document.forms['loginForm'].submit()\">" );

I can't see how those two strings accomplish what the comment says they accomplish and I'm not sure what they're even doing actually. Should there be an 'if' statement wrapped around all that?

도움이 되었습니까?

해결책

<meta http-equiv="refresh" content="30;URL=./?logout=1">

Tells the browser to redirect to ./?logout=1 in 30 seconds.

<body onload="document.forms['loginForm'].submit()">

Looks for a form called loginForm and submits it.

If the page loads and and the form submits in less than thirty seconds, everything will work as expected. If not, it assume JavaScript is not enabled. This is a bad solution. Users without Javascript have to wait 30 seconds before being redirected. And there is a real chance of a false positive over a slow network connection.

Try the noscript tag:

<noscript><meta http-equiv="refresh" content="0;URL=./?logout=1"></noscript>

다른 팁

It looks to me like it is using javascript to submit the login form and that will not happen if javascript is not enabled, in which case the meta tag is going to refresh the page and logout.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top