Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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) {
                 
                    //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
XML
<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
Posted
Updated 12-Jul-19 8:25am
Comments
ZurdoDev 14-May-20 8:00am    
I'm not exactly sure what you are asking. If the user is no longer authenticated then of course it will prompt for credentials again. If you don't want a prompt you need to setup anonymous access for the page but then you don't get the user account.

Sounds like you also want to send a request to check if the session is still active? Unless something has changed recently you can't do that. Why? Because the act of sending the request resets the Session's counter. The only way I know of is to keep track in the client side with a timer, which really is not a good option, in my opinion.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900