web services - Redirect from Webmethod in Asp.Net -
am new asp.net programming, have started web project. calling webmethod aspx page using json below:
<script type="text/javascript"> function getlogin() { var username = document.getelementbyid('textbox1').value; $.ajax({ type: "post", url: "services/logservice.asmx/authenticatelogin", data: "{'username':'" +username.tostring()+ "'}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (response) { alert(response.d) }, error: function (xhr, status, error) { // alert(textstatus); displayerror(xhr); } }); } function displayerror(xhr) { var msg = json.parse(xhr.responsetext); alert(msg.message); } </script>
and webmethod :
[webmethod] public string authenticatelogin(string username) { loginbo loginbo = new loginbo(); loginbo.username = username.tostring().trim(); string result = ""; try { logindao logindao = daofactory.getdaofactory().getlogindao(); result = logindao.selectuser(loginbo); } catch (dbconnectionexception) { //result = "db conenction"; throw new exception("db connection down"); } catch (invalidloginexception) { //httpresponse res = new httpresponse(); //httpresponse.referenceequals.redirect("~/login.aspx"); throw new invalidloginexception("login invalid"); } catch (exception) { throw new exception("uanble fetch "); } int ctx = context.response.statuscode; return result; }
after successful authentication, want redirect user aspx page.
what best practice ?
thanks samuel
add redirect success section of getlogin()
function:
success: function (response) { alert(response.d); windows.location.href = "http://url.for.redirect"; }
(or use some other method redirecting within jquery/javascript).
Comments
Post a Comment