i have a Ajax request is to load food is execute when click on a Div lets called loadDiv
Problem is when authentication expires and we try to access Web service, browser prompt a message box asking credentials for server.
Or if I open aspx page in two tab and then sign out from one tab(it will call FormsAuthentication.SignOut()), then i try to access web service by clicking loadDiv in
the second tab in browser it prompt same box for user name and Password
.ie the page does not redirect to login page as Get request done.
I want to a method to verify whether user login section expired or not if expired redirect to login page
Ajax Method
$.ajax({
type: "POST",
url: urlString,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: dateAndPatientID,
success: function(response) {
var jposts = response.d;
var itemc = false;
var calcc = 0;
$.each(jposts, function(index, jpost) {
});
if (txt == "")
txt = "No items To display";
$('#divfoodDetails' + id).append(txt);
},
failure: function(msg) {
details = 'Cannot find Food Items';
}
});
and I use Form Authentication for my application in web config
<system.web>
<authentication mode="Forms">
<forms loginUrl="Index.aspx" protection="All" name=".OTS"></forms>
</authentication>
</system.web>
<location path="UserArea">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Login Method in Login page Contain
string url = "UserArea/" + obj1.GetErrorURLForUserType().Substring(3);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
nickname,
DateTime.Now,
DateTime.Now.AddMinutes(60),
false,
obj.UserID.ToString(),
FormsAuthentication.FormsCookiePath);
string enrypted = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, enrypted);
Response.Cookies.Add(cookie);
Session["SelectedMenuID"] = null;
string[] addressarray = url.Split('/');
Session["MenuString"] = addressarray[addressarray.Length - 1];
Response.Redirect(url, false);
i found this question and
webservice ask for Username and Password For server insted of redirecting to login page[
^]
i want o know if there any other way to authenicate request for web service PLZ help.or give some useful link