I am using asp.net and I have $.ajax calls in my web application for every request to the server.
我正在使用asp.net,我在我的Web应用程序中为服务器的每个请求都有$ .ajax调用。
I want to redirect the user to the Login page on session end.
我想将用户重定向到会话结束时的登录页面。
In my web.config I set:
在我的web.config中我设置:
<authentication mode="Forms">
<forms name=".CovertixAuthenticated" defaultUrl="Default.aspx" loginUrl="LoginPage.aspx" slidingExpiration="true" cookieless="UseCookies" protection="All" timeout="1"/>
</authentication>
<sessionState mode="InProc" cookieless="UseCookies" timeout="1"/>
and I check in .ajaxError:
我签入.ajaxError:
$(document).ajaxError(function(xhr, props) {
if (props.status == 401) {
var ParentUrl = encodeURIComponent(window.parent.location.href);
//alert(getLoginPage());
document.location.href = getLoginPage() + "?ReturnUrl=" + ParentUrl;
}
});
The problem is I get responseCode = 500 (Internal server error)
问题是我得到responseCode = 500(内部服务器错误)
What is the best way to check if session expired on ajax call, or how can I redirect the user to the login page automatically when session ends?
检查会话是否在ajax调用上过期的最佳方法是什么,或者如何在会话结束时自动将用户重定向到登录页面?
1 个解决方案
#1
0
Thanks guys for the help!
谢谢大家的帮助!
I just forgot to add to my web.config:
我只是忘了添加到我的web.config:
<location path="MyPage.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Now I get 401 as expected!
现在我按预期得到了401!
#1
0
Thanks guys for the help!
谢谢大家的帮助!
I just forgot to add to my web.config:
我只是忘了添加到我的web.config:
<location path="MyPage.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Now I get 401 as expected!
现在我按预期得到了401!