简体   繁体   中英

ASP.NET Response.Redirect() doesn't work without try/catch

I have a trouble, which I didn't get earlier with the ASP.NET . I can't redirect to the some location with the method Response.Redirect()

I've read another topics and may tell you, what exactly I have tried:

  • I don't use Response.Redirect() in try/catch block, which may cause an ThreadAbortException ( but if you try to ignore this exception - you must be redirected, even in this case I can't redirect )
  • I've tried to use Boolean values , where using them as a flag at the end of Page_Load() method to make a redirection
  • I've tried to use even the JS-call with the location property, but ASP.NET ignores it... As I see I could call any function in JS and it will be ignored
  • Tried to set to the false the value of the second parameter of method Response.Redirect()

I shall paste ONLY one of the variants, because as I wrote upper I tried different ways, but no success.

Code: http://ideone.com/Y8Fwpt

Redirect on 58th line doesn't work even there is a handler for the ThreadAbortException . Calling JS-scenario on 62nd line - ignores too.

Even if I remove try/catch block - nothing will change.

Please, help me to fix this issue!

I could make the redirect work if I removed the onclick() you have on the login form - I think your query string isn't coming across correctly, so you wind up just doing a quick page refresh. So, I would make two suggestions:

One , remove all the script & Ajax stuff you're trying to do, and get it working with normal postbacks first - then you can go back and try the async stuff.

Two , I wouldn't mess with creating your own cookies at this point - the MySQLConnector library has Membership and Role providers you can use that are built to connect to MySQL databases.

In a nutshell, the idiom I hold near and dear when I'm developing is "do the simplest thing that works," which in this case is just "classic" ASP.NET postbacks...

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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