1

I am facing a strange issue and unable to find a way out. I have a web api application which is working fine until it times out. At this point when i make a ajax call server response is empty and an additional response is received with Login URL. Web API CAll 1

I thought of catching response and read location header to identify if it contains login URL with no success. How should we handle such scenario in web api ajax calls?

1 Answer 1

3

You could set the SuppressFormsAuthenticationRedirect property to prevent this behavior. For example in your global.asax:

protected void Application_EndRequest(object sender, EventArgs e)
{
    HttpApplication context = (HttpApplication)sender;
    context.Response.SuppressFormsAuthenticationRedirect = true;
}

Setting this will have a global impact over both your ASP.NET MVC and Web API parts.

If you want to do this only for your Web API endpoints, you could inspect the context.Request.Url and conditionally do it only for /api endpoints.

If you are using newer versions of the framework you might also consider reading this post.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.