I am using asp.net and I have $.ajax calls in my web application for every request to the server.
I want to redirect the user to the Login page on session end.
In my web.config I set:
<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:
$(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)
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?
Thanks guys for the help!
I just forgot to add to my web.config:
<location path="MyPage.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Now I get 401 as expected!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments