Asp.Net编程新手,刚刚开始了一个web项目。 是从ASPX页面使用JSON象下面这样调用一个WebMethod:Asp.Net中的Webmethod重定向
<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>
而且的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 is Down");
}
catch (InvalidLoginException)
{
//HttpResponse res = new HttpResponse();
//HttpResponse.ReferenceEquals.Redirect("~/Login.aspx");
throw new InvalidLoginException("Login Is Invalid");
}
catch (Exception)
{
throw new Exception("Uanble to Fetch ");
}
int ctx = Context.Response.StatusCode;
return result;
}
认证成功后,我想用户重定向到另一个aspx页面。
最佳做法是什么?
感谢 塞缪尔
埃利斯,什么用于重定向window.location.href或window.location.replace? –
请参阅[本文](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery) - 它讨论了不同的选项及其优点/缺点。似乎更喜欢'replace'方法。 –