Bhaskar CEAD
Bhaskar CEAD

Reputation: 1

Azure active directory with ASP.NET MVC

we have an ASP.NET MVC web application where we azure b2c authentication. There are several controllers and views in mvc application. Whenever user wants to access to controller we have checking whether he is signed in or not? On the basis of that if user is already signed then only we are giving access to him. On every controller's .cs file we have put code like :

if (Request.IsAuthenticated)
      {
       some code;
        return View();
      }
      else
      {
        return RedirectToAction("Login", "Home");
      }

This type of code on each action method of controller. Its working fine but most of the times it automatically kicked user out of the system frequently on login page to re-sign again.

Ca anyone tell me how can I centarlized this type of code in mvc application for each controller so that it should not kicked me out of the system. Please help. Thanks.

Upvotes: 0

Views: 280

Answers (1)

Fei Xue
Fei Xue

Reputation: 14649

To restrict access to an ASP.NET MVC view, you restrict access to the action method that renders the view. To accomplish this, the MVC framework provides the AuthorizeAttribute class.

Its working fine but most of the times it automatically kicked user out of the system frequently on login page to re-sign again.

Did you mean that that after the web session is expired, then the web application redirect the web request to the login page? If I understood correctly, this is a expected behavior. And if you want the web application to keep alive when the user is active, you can enable the SlidingExpiration.

Upvotes: 1

Related Questions