Click here to Skip to main content
14,240,044 members
Rate this:
Please Sign up or sign in to vote.
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
            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) {
                    //Some work
                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
        <authentication mode="Forms">
            <forms loginUrl="Index.aspx" protection="All" name=".OTS"></forms>
    <location path="UserArea">
                <deny users="?"/>

Login Method in Login page Contain

string url = "UserArea/" + obj1.GetErrorURLForUserType().Substring(3);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        string enrypted = FormsAuthentication.Encrypt(ticket);
                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, enrypted);
                        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
Updated 12-Jul-19 8:25am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100