public IActionResult Index()
 {
     try
     {
         string errorMessage        = string.Empty;
         var    listParams          = new List <KeyValuePair <string, string> >();
         var    httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
         var    result = httpContextAccessor.HttpContext.Session.GetString("LoginDetails");
         var    obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResData>(result);
         listParams.Add(new KeyValuePair <string, string>("customerId", Convert.ToString(obj.customerId)));
         var response = new CallService().GetResponse <List <ProfileResponse> >("geCustomerProfile", listParams, ref errorMessage);
         if (string.IsNullOrEmpty(errorMessage))
         {
             if (response.Count > 1)
             {
                 response[0].aepsBalance = response.Where(m => m.walletTypeId == 2).FirstOrDefault().customerEffectiveBalance;
             }
             return(View(response[0]));
         }
         else
         {
             ViewData["ErrorMessage"] = errorMessage;
             return(View());
         }
     }
     catch (Exception ex)
     {
         ViewData["ErrorMessage"] = ex.Message;
         return(View());
     }
 }
        public static HttpContextAccessor CreateHttpContextAccessor(RequestTelemetry requestTelemetry = null, ActionContext actionContext = null)
        {
            var services = new ServiceCollection();

            var request = new DefaultHttpContext().Request;
            request.Method = "GET";
            request.Path = new PathString("/Test");
            var contextAccessor = new HttpContextAccessor() { HttpContext = request.HttpContext };

            services.AddSingleton<IHttpContextAccessor>(contextAccessor);

            if (actionContext != null)
            {
                var si = new ActionContextAccessor();
                si.ActionContext = actionContext;
                services.AddSingleton<IActionContextAccessor>(si);
            }

            if (requestTelemetry != null)
            {
                services.AddSingleton<RequestTelemetry>(requestTelemetry);
            }

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            contextAccessor.HttpContext.RequestServices = serviceProvider;

            return contextAccessor;
        }
        public void InitializeDoesNotThrowIfHttpContextIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = null };

            var initializer = new DomainNameRoleInstanceTelemetryInitializer(ac);

            initializer.Initialize(new RequestTelemetry());
        }
        public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };

            var initializer = new WebUserTelemetryInitializer(ac);

            initializer.Initialize(new RequestTelemetry());
        }
        public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };

            var initializer = new OperationNameTelemetryInitializer(ac, new DiagnosticListener(TestListenerName));

            initializer.Initialize(new RequestTelemetry());
        }
        public void InitializeDoesNotThrowIfHttpContextIsUnavailable()
        {
            var ac = new HttpContextAccessor() { HttpContext = null };

            var initializer = new WebSessionTelemetryInitializer(ac);

            initializer.Initialize(new RequestTelemetry());
        }
        public void CreateHttpContextSetsHttpContextAccessor()
        {
            // Arrange
            var accessor       = new HttpContextAccessor();
            var contextFactory = new HttpContextFactory(Options.Create(new FormOptions()), new MyServiceScopeFactory(), accessor);

            // Act
            var context = contextFactory.Create(new FeatureCollection());

            // Assert
            Assert.Same(context, accessor.HttpContext);
        }
        public void CreateHttpContextSetsHttpContextAccessor()
        {
            // Arrange
            var accessor       = new HttpContextAccessor();
            var contextFactory = new HttpContextFactory(Options.Create(new FormOptions()), accessor);

            // Act
            var context = contextFactory.Create(new FeatureCollection());

            // Assert
            Assert.True(ReferenceEquals(context, accessor.HttpContext));
        }
示例#9
0
 public string Get(string key)
 {
     try
     {
         var httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
         return(httpContextAccessor.HttpContext.Request.Cookies[key]);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public async Task HttpContextAccessor_GettingHttpContextReturnsHttpContext()
        {
            var accessor = new HttpContextAccessor();

            var context = new DefaultHttpContext();

            context.TraceIdentifier = "1";
            accessor.HttpContext    = context;

            await Task.Delay(100);

            Assert.Same(context, accessor.HttpContext);
        }
        public async Task HttpContextAccessor_GettingHttpContextReturnsNullHttpContextIfDifferentTraceIdentifier()
        {
            var accessor = new HttpContextAccessor();

            var context = new DefaultHttpContext();

            context.TraceIdentifier = "1";
            accessor.HttpContext    = context;

            var checkAsyncFlowTcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
            var waitForNullTcs    = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
            var afterNullCheckTcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

            ThreadPool.QueueUserWorkItem(async _ =>
            {
                // The HttpContext flows with the execution context
                Assert.Same(context, accessor.HttpContext);

                checkAsyncFlowTcs.SetResult(null);

                await waitForNullTcs.Task;

                try
                {
                    Assert.Null(accessor.HttpContext);

                    afterNullCheckTcs.SetResult(null);
                }
                catch (Exception ex)
                {
                    afterNullCheckTcs.SetException(ex);
                }
            });

            await checkAsyncFlowTcs.Task;

            // Reset the trace identifier on the first request
            context.TraceIdentifier = null;

            // Set a new http context
            var context2 = new DefaultHttpContext();

            context2.TraceIdentifier = "2";
            accessor.HttpContext     = context2;

            waitForNullTcs.SetResult(null);

            Assert.Same(context2, accessor.HttpContext);

            await afterNullCheckTcs.Task;
        }
示例#12
0
        public void DisposeHttpContextSetsHttpContextAccessorToNull()
        {
            // Arrange
            var accessor       = new HttpContextAccessor();
            var contextFactory = new HttpContextFactory(Options.Create(new FormOptions()), accessor);

            // Act
            var context = contextFactory.Create(new FeatureCollection());

            // Assert
            Assert.Same(context, accessor.HttpContext);

            contextFactory.Dispose(context);

            Assert.Null(accessor.HttpContext);
        }
        public IActionResult ResetTPIN(PasswordSettingReq req)
        {
            var    httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
            var    result       = httpContextAccessor.HttpContext.Session.GetString("LoginDetails");
            var    obj          = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResData>(result);
            string errorMessage = string.Empty;
            var    parameter    = new { mobileNumber = obj.mobileNumber, passwordType = 2 };
            var    response     = new CallService().PostResponse <ChangePasswordResponse>(APIMethodConst.ResendPassword, parameter, ref errorMessage);

            if (string.IsNullOrEmpty(errorMessage))
            {
                return(Json(new { success = true }));
            }
            else
            {
                return(Json(new { success = false }));
            }
        }
        public IActionResult ChangeMPIN(PasswordSettingReq req)
        {
            var    httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
            var    result       = httpContextAccessor.HttpContext.Session.GetString("LoginDetails");
            var    obj          = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResData>(result);
            string errorMessage = string.Empty;
            var    parameter    = new { customerId = obj.customerId, passwordType = 1, oldPassword = HashShA1(req.oldPassword), newPassword = HashShA1(req.newPassword) };
            var    response     = new CallService().PostResponse <int>(APIMethodConst.ChangePassword, parameter, ref errorMessage);

            if (string.IsNullOrEmpty(errorMessage))
            {
                return(Json(new { success = true, errorMessage = "Password Changed" }));
            }
            else
            {
                return(Json(new { success = false, errorMessage = errorMessage }));
            }
        }
        public async Task HttpContextAccessor_GettingHttpContextReturnsNullHttpContextIfSetToNull()
        {
            var accessor = new HttpContextAccessor();

            var context = new DefaultHttpContext();

            accessor.HttpContext = context;

            var checkAsyncFlowTcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
            var waitForNullTcs    = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
            var afterNullCheckTcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

            ThreadPool.QueueUserWorkItem(async _ =>
            {
                // The HttpContext flows with the execution context
                Assert.Same(context, accessor.HttpContext);

                checkAsyncFlowTcs.SetResult(null);

                await waitForNullTcs.Task;

                try
                {
                    Assert.Null(accessor.HttpContext);

                    afterNullCheckTcs.SetResult(null);
                }
                catch (Exception ex)
                {
                    afterNullCheckTcs.SetException(ex);
                }
            });

            await checkAsyncFlowTcs.Task;

            // Null out the accessor
            accessor.HttpContext = null;

            waitForNullTcs.SetResult(null);

            Assert.Null(accessor.HttpContext);

            await afterNullCheckTcs.Task;
        }
示例#16
0
        public List <MenuRes> BindSideMenu()
        {
            var httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
            var result    = httpContextAccessor.HttpContext.Session.GetString("LoginDetails");
            var obj       = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResData>(result);
            var listParam = new List <KeyValuePair <string, string> >();

            listParam.Add(new KeyValuePair <string, string>("portalId", Convert.ToString(PortalDetails.PortalId)));
            listParam.Add(new KeyValuePair <string, string>("customerRoleId", Convert.ToString(obj.customerRoleId)));
            string errorMessage = string.Empty;
            var    response     = new CallService().GetResponse <List <MenuRes> >(APIMethodConst.GetMenusPortalRoleId, listParam, ref errorMessage);

            if (string.IsNullOrEmpty(errorMessage))
            {
                return(response);
            }
            else
            {
                return(null);
            }
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
            var result = httpContextAccessor.HttpContext.Session.GetString("LoginDetails");

            if (result == null)
            {
                context.Result = new RedirectToRouteResult(new RouteValueDictionary {
                    { "Area", "" }, { "Controller", "Login" },
                    { "Action", "Index" }
                });
            }
            var menus = new SessionUtility().GetMenuSession();

            if (menus != null)
            {
                Controller controller = context.Controller as Controller;
                controller.ViewBag.MenuList = menus;
            }

            base.OnActionExecuting(context);
        }
示例#18
0
        public void Set(string key, string value, int?expireTime)
        {
            try
            {
                CookieOptions option = new CookieOptions();

                if (expireTime.HasValue)
                {
                    option.Expires = DateTime.Now.AddMinutes(expireTime.Value);
                }
                else
                {
                    option.Expires = DateTime.Now.AddMilliseconds(10);
                }

                var httpContextAccessor = new Microsoft.AspNetCore.Http.HttpContextAccessor();
                httpContextAccessor.HttpContext.Response.Cookies.Append(key, value);
            }
            catch (Exception)
            {
            }
        }
示例#19
0
 public Logger(IConfiguration config)
 {
     IHttpContextAccessor accessor = new HttpContextAccessor();
     AccountId = () => accessor.HttpContext?.User.Id();
     Config = config;
 }
        public void HttpContextAccessor_GettingHttpContextWithOutSettingReturnsNull()
        {
            var accessor = new HttpContextAccessor();

            Assert.Null(accessor.HttpContext);
        }
 public static IdentityServerContext Create(HttpContext context = null, IdentityServerOptions options = null)
 {
     var accessor = new HttpContextAccessor();
     accessor.HttpContext = context ?? new DefaultHttpContext();
     return new IdentityServerContext(accessor, options ?? new IdentityServerOptions());
 }
 public AspNetCorePrincipalAccessor(HttpContextAccessor httpContextAccessor)
 {
     _httpContextAccessor = httpContextAccessor;
 }