Base solution for your next web application
Open Closed

Common code for controller #4174


User avatar
0
pankajmathur created

Hi,

I want to write the below given common code in all the methods which return ActionResult in my controller. There are about 100 controllers in my application. What is the best way to handle this?

var currentloginInfo = RequestSessionCache.GetCurrentLoginInformationsAsync().Result;
           if (currentloginInfo.Tenant.GetSubscriptionExpiringDayCount() < 0)
            {
                return RedirectToAction("SelectEdition", "SubscriptionManagement", new { editionPaymentType = "Upgrade" });
            }

Regards, Abinesh


3 Answer(s)
  • User Avatar
    0
    alirizaadiyahsi created

    Hi @pankajmathur,

    Actually expired users are not logging in. When a tenant subscription expired, this user status is changing to Active=0 by a scheduled job. So you cant get "currentloginInfo" for expired user.

  • User Avatar
    0
    pankajmathur created

    We have changed the default behavior as we would like to user to login within 30 days of expiry, however he will see only the payment screen and unless he has paid cannot goto any other controller page.

  • User Avatar
    0
    alirizaadiyahsi created

    Ok, you can use actionfilters for this.

    Check detailed explanation for actionfilters here: <a class="postlink" href="https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters">https://docs.microsoft.com/en-us/aspnet ... rs/filters</a>