Bharat Bharat - 1 month ago 18
C# Question

Stop Async call in Global.aspx

i have two mvc applications in one solution.

now i need to maintain session when user redirects from one application to another.

so what my logic is,


  • passed GUID in URL.

  • get GUID in another projects Global.asax file using Init() method.

  • Log in another user.



i done whole code, added below.

now, i am getting call in Init() method but it also calls other methods which are passed in URl.

i.e. call becomes asynch, so because of that, user redirected to other page.

do i need to change my logic or just code?
below is my Global.asax file code.

public override void Init()
{
var userId = Guid.Parse(Request["UserGUID"].ToString());
if (userId != null && userId == Guid.Parse("1B541D9A-AC3E-466F-897B-6F9033F4533C"))

//my logic of login management
}

Answer

After more then 8 hours of R&D, i found solution that really helped me.

Actually my way is proper but the method is not right.

Application_AcquireRequestState

is the proper method for my scenario.

my code is :

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

    public void Application_AcquireRequestState(object sender, EventArgs e)
    {
        var userId = HttpContext.Current.Request["UserGUID"];

        if (userId != null)
        {
            Session["UserGuid"] = Guid.Parse(userId.ToString());

            //My logic for session handling..
        }
    }
}
Comments