Ejemplo n.º 1
0
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }

                if (!context.HttpContext.Request.Method.Equals(WebRequestMethods.Http.Get, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
                {
                    return;
                }

                var currentIpAddress = _webHelper.MevcutIpAdresiAl();

                if (string.IsNullOrEmpty(currentIpAddress))
                {
                    return;
                }

                if (!currentIpAddress.Equals(_workContext.MevcutKullanıcı.SonIPAdresi, StringComparison.InvariantCultureIgnoreCase))
                {
                    _workContext.MevcutKullanıcı.SonIPAdresi = currentIpAddress;
                    _kullanıcıServisi.KullanıcıGüncelle(_workContext.MevcutKullanıcı);
                }
            }
Ejemplo n.º 2
0
        protected void Application_Start()
        {
            //Database.SetInitializer<NameOfDbContext>(new DropCreateDatabaseIfModelChanges<NameOfDbContext>());
            //most of API providers require TLS 1.2 nowadays
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //disable "X-AspNetMvc-Version" header name
            MvcHandler.DisableMvcResponseHeader = true;

            //initialize engine context
            EngineContext.Initialize(false);

            bool databaseInstalled = DataAyarlarıYardımcısı.DatabaseYüklendi();

            if (databaseInstalled)
            {
                //remove all view engines
                ViewEngines.Engines.Clear();
                //except the themeable razor view engine we use
                ViewEngines.Engines.Add(new TemalanabilirRazorGörünümMotoru());
            }

            //Add some functionality on top of the default ModelMetadataProvider
            //ModelMetadataProviders.Current = new NopMetadataProvider();

            //Registering some regular mvc stuff
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);

            //fluent validation
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            //ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new NopValidatorFactory()));

            if (databaseInstalled)
            {
                //start scheduled tasks

                /*
                 * TaskManager.Instance.Initialize();
                 * TaskManager.Instance.Start();
                 *
                 * //miniprofiler
                 * if (EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore)
                 * {
                 *  GlobalFilters.Filters.Add(new ProfilingActionFilter());
                 * }
                 */
                //log application start
                try
                {
                    //log
                    //var logger = EngineContext.Current.Resolve<ILogger>();
                    //logger.Information("Application started", null, null);
                }
                catch (Exception)
                {
                    //don't throw new exception if occurs
                }
            }
        }
Ejemplo n.º 3
0
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }

                if (!context.HttpContext.Request.Method.Equals(WebRequestMethods.Http.Get, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
                {
                    return;
                }

                //update last activity date
                if (_workContext.MevcutKullanıcı.SonİşlemTarihi.AddMinutes(1.0) < DateTime.UtcNow)
                {
                    _workContext.MevcutKullanıcı.SonİşlemTarihi = DateTime.UtcNow;
                    _kullanıcıServisi.KullanıcıGüncelle(_workContext.MevcutKullanıcı);
                }
            }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            if (filterContext == null || filterContext.HttpContext == null || filterContext.HttpContext.Request == null)
            {
                return;
            }

            //Alt yöntemlere filtre uygulamayın
            if (filterContext.IsChildAction)
            {
                return;
            }

            //Yalnızca GET istekleri
            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var workContext = EngineContext.Current.Resolve <IWorkContext>();
            var kullanıcı   = workContext.MevcutKullanıcı;

            //update last activity date
            if (kullanıcı.SonİşlemTarihi.AddMinutes(1.0) < DateTime.UtcNow)
            {
                var kullanıcıServisi = EngineContext.Current.Resolve <IKullanıcıServisi>();
                kullanıcı.SonİşlemTarihi = DateTime.UtcNow;
                kullanıcıServisi.KullanıcıGüncelle(kullanıcı);
            }
        }
Ejemplo n.º 5
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            if (_görmezdenGel)
            {
                return;
            }
            if (filterContext.IsChildAction)
            {
                return;
            }
            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }
            var güvenlikAyarları = EngineContext.Current.Resolve <GüvenlikAyarları>();

            if (!güvenlikAyarları.YöneticiAlanıiçinXsrfKorumasınıEtkinleştir)
            {
                return;
            }
            var doğrulayıcı = new ValidateAntiForgeryTokenAttribute();

            doğrulayıcı.OnAuthorization(filterContext);
        }
Ejemplo n.º 6
0
        public static void UseCulture(this IApplicationBuilder application)
        {
            //check whether database is installed
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            application.UseMiddleware <CultureMiddleware>();
        }
Ejemplo n.º 7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null || filterContext.HttpContext == null)
            {
                return;
            }

            if (_yoksay)
            {
                return;
            }

            HttpRequestBase istek = filterContext.HttpContext.Request;

            if (istek == null)
            {
                return;
            }

            string actionName = filterContext.ActionDescriptor.ActionName;

            if (String.IsNullOrEmpty(actionName))
            {
                return;
            }

            string controllerName = filterContext.Controller.ToString();

            if (String.IsNullOrEmpty(controllerName))
            {
                return;
            }

            //child metod ise uygulama
            if (filterContext.IsChildAction)
            {
                return;
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            var izinServisi = EngineContext.Current.Resolve <IİzinServisi>();
            var publicStoreAllowNavigation = izinServisi.YetkiVer(StandartİzinSağlayıcı.Navigasyonİzinli);

            if (publicStoreAllowNavigation)
            {
                return;
            }

            filterContext.Result = new HttpUnauthorizedResult();
        }
        public static void AddThemes(this IServiceCollection services)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            //themes support
            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new TemalanabilirViewKonumuAyırıcı());
            });
        }
Ejemplo n.º 9
0
 public async Task Invoke(HttpContext context, IWebYardımcısı webHelper)
 {
     if (DataAyarlarıYardımcısı.DatabaseYüklendi())
     {
         //keep alive page requested (we ignore it to prevent creating a guest customer records)
         var keepAliveUrl = $"{webHelper.SiteKonumuAl()}keepalive/index";
         if (webHelper.SayfanınUrlsiniAl(false).StartsWith(keepAliveUrl, StringComparison.InvariantCultureIgnoreCase))
         {
             return;
         }
     }
     //or call the next middleware in the request pipeline
     await _next(context);
 }
Ejemplo n.º 10
0
        protected void SetWorkingCulture()
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            //ignore static resources
            var webHelper = EngineContext.Current.Resolve <IWebYardımcısı>();

            if (webHelper.SabitKaynak(this.Request))
            {
                return;
            }

            //keep alive page requested (we ignore it to prevent creation of guest customer records)
            string keepAliveUrl = string.Format("{0}keepalive/index", webHelper.SiteKonumuAl());

            if (webHelper.SayfanınUrlsiniAl(false).StartsWith(keepAliveUrl, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }


            if (webHelper.SayfanınUrlsiniAl(false).StartsWith(string.Format("{0}Yönetim", webHelper.SiteKonumuAl()),
                                                              StringComparison.InvariantCultureIgnoreCase))
            {
                //admin area


                //always set culture to 'en-US'
                //we set culture of admin area to 'en-US' because current implementation of Telerik grid
                //doesn't work well in other cultures
                //e.g., editing decimal value in russian culture
                GenelYardımcı.TelerikKültürAyarla();
            }
            else
            {
                //public store

                /*
                 * var workContext = EngineContext.Current.Resolve<IWorkContext>();
                 * var culture = new CultureInfo(workContext.WorkingLanguage.LanguageCulture);
                 * Thread.CurrentThread.CurrentCulture = culture;
                 * Thread.CurrentThread.CurrentUICulture = culture;
                 */
            }
        }
        public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfigurationRoot configuration)
        {
            services.ConfigureStartupConfig <Config>(configuration.GetSection("Rota"));
            services.ConfigureStartupConfig <HostingAyarları>(configuration.GetSection("Hosting"));
            services.AddHttpContextAccessor();
            var engine = EngineContext.Create();

            engine.Initialize(services);
            var serviceProvider = engine.ConfigureServices(services, configuration);

            if (DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                EngineContext.Current.Resolve <ILogger>().Bilgi("Uygulama başladı", null, null);
            }

            return(serviceProvider);
        }
Ejemplo n.º 12
0
        public async Task Invoke(Microsoft.AspNetCore.Http.HttpContext context, IWebYardımcısı webHelper)
        {
            //whether database is installed
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                var installUrl = $"{webHelper.SiteKonumuAl()}install";
                if (!webHelper.SayfanınUrlsiniAl(false).StartsWith(installUrl, StringComparison.InvariantCultureIgnoreCase))
                {
                    //redirect
                    context.Response.Redirect(installUrl);
                    return;
                }
            }

            //or call the next middleware in the request pipeline
            await _next(context);
        }
Ejemplo n.º 13
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            if (filterContext == null || filterContext.HttpContext == null || filterContext.HttpContext.Request == null)
            {
                return;
            }

            //Alt yöntemlere filtre uygulamayın
            if (filterContext.IsChildAction)
            {
                return;
            }

            //Yalnızca GET istekleri
            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var kullanıcıAyarları = EngineContext.Current.Resolve <KullanıcıAyarları>();

            if (!kullanıcıAyarları.SiteSonZiyaretSayfası)
            {
                return;
            }

            var webYardımcısı = EngineContext.Current.Resolve <IWebYardımcısı>();
            var sayfaUrl      = webYardımcısı.SayfanınUrlsiniAl(true);

            if (!String.IsNullOrEmpty(sayfaUrl))
            {
                var workContext           = EngineContext.Current.Resolve <IWorkContext>();
                var genelÖznitelikServisi = EngineContext.Current.Resolve <IGenelÖznitelikServisi>();

                var öncekiSayfaUrl = workContext.MevcutKullanıcı.ÖznitelikAl <string>(SistemKullanıcıÖznitelikAdları.SonZiyaretEdilenSayfa);
                if (!sayfaUrl.Equals(öncekiSayfaUrl))
                {
                    genelÖznitelikServisi.ÖznitelikKaydet(workContext.MevcutKullanıcı, SistemKullanıcıÖznitelikAdları.SonZiyaretEdilenSayfa, sayfaUrl);
                }
            }
        }
Ejemplo n.º 14
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //ignore static resources
            var webHelper = EngineContext.Current.Resolve <IWebYardımcısı>();

            if (webHelper.SabitKaynak(this.Request))
            {
                return;
            }

            //keep alive page requested (we ignore it to prevent creating a guest customer records)
            string keepAliveUrl = string.Format("{0}keepalive/index", webHelper.SiteKonumuAl());

            if (webHelper.SayfanınUrlsiniAl(false).StartsWith(keepAliveUrl, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            //ensure database is installed
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                string installUrl = string.Format("{0}install", webHelper.SiteKonumuAl());
                if (!webHelper.SayfanınUrlsiniAl(false).StartsWith(installUrl, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.Response.Redirect(installUrl);
                }
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            /*
             * //miniprofiler
             * if (EngineContext.Current.Resolve<SiteBilgiAyarları>().DisplayMiniProfilerInPublicStore)
             * {
             *  MiniProfiler.Start();
             *  //store a value indicating whether profiler was started
             *  HttpContext.Current.Items["nop.MiniProfilerStarted"] = true;
             * }
             */
        }
Ejemplo n.º 15
0
        public static void UseRotaExceptionHandler(this IApplicationBuilder application)
        {
            var nopConfig                = EngineContext.Current.Resolve <Config>();
            var hostingEnvironment       = EngineContext.Current.Resolve <IHostingEnvironment>();
            var useDetailedExceptionPage = nopConfig.DisplayFullErrorStack || hostingEnvironment.IsDevelopment();

            if (useDetailedExceptionPage)
            {
                application.UseDeveloperExceptionPage();
            }
            else
            {
                application.UseExceptionHandler("/errorpage.htm");
            }

            application.UseExceptionHandler(handler =>
            {
                handler.Run(context =>
                {
                    var exception = context.Features.Get <IExceptionHandlerFeature>()?.Error;
                    if (exception == null)
                    {
                        return(Task.CompletedTask);
                    }

                    try
                    {
                        if (DataAyarlarıYardımcısı.DatabaseYüklendi())
                        {
                            //get current customer
                            var currentCustomer = EngineContext.Current.Resolve <IWorkContext>().MevcutKullanıcı;

                            //log error
                            EngineContext.Current.Resolve <ILogger>().Hata(exception.Message, exception, currentCustomer);
                        }
                    }
                    finally
                    {
                        throw exception;
                    }
                });
            });
        }
Ejemplo n.º 16
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null || filterContext.HttpContext == null || filterContext.HttpContext.Request == null)
            {
                return;
            }

            //Alt yöntemlere filtre uygulamayın
            if (filterContext.IsChildAction)
            {
                return;
            }

            var actionName = filterContext.ActionDescriptor.ActionName;

            if (string.IsNullOrEmpty(actionName) || actionName.Equals("ŞifreDeğiştir", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            var controllerName = filterContext.Controller.ToString();

            if (string.IsNullOrEmpty(controllerName) || controllerName.Equals("Kullanıcı", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            //Mevcut kullanıcı al
            var kullanıcı = EngineContext.Current.Resolve <IWorkContext>().MevcutKullanıcı;

            //Şifre geçerliliğini kontrol et
            if (kullanıcı.ParolaSüresiDoldu())
            {
                var şifreDeğiştimeUrlsi = new UrlHelper(filterContext.RequestContext).RouteUrl("KullanıcıŞifreDeğiştirme");
                filterContext.Result = new RedirectResult(şifreDeğiştimeUrlsi);
            }
        }
Ejemplo n.º 17
0
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }

                if (!context.HttpContext.Request.Method.Equals(WebRequestMethods.Http.Get, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
                {
                    return;
                }

                if (!_kullanıcıAyarları.SiteSonZiyaretSayfası)
                {
                    return;
                }

                var pageUrl = _webHelper.SayfanınUrlsiniAl(true);

                if (string.IsNullOrEmpty(pageUrl))
                {
                    return;
                }

                var previousPageUrl = _workContext.MevcutKullanıcı.ÖznitelikAl <string>(SistemKullanıcıÖznitelikAdları.SonZiyaretEdilenSayfa);

                if (!pageUrl.Equals(previousPageUrl, StringComparison.InvariantCultureIgnoreCase))
                {
                    _genelÖznitelikServisi.ÖznitelikKaydet(_workContext.MevcutKullanıcı, SistemKullanıcıÖznitelikAdları.SonZiyaretEdilenSayfa, pageUrl);
                }
            }
Ejemplo n.º 18
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            if (filterContext == null || filterContext.HttpContext == null || filterContext.HttpContext.Request == null)
            {
                return;
            }

            //Alt yöntemlere filtre uygulamayın
            if (filterContext.IsChildAction)
            {
                return;
            }

            //Yalnızca GET istekleri
            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var webYardımcısı = EngineContext.Current.Resolve <IWebYardımcısı>();

            //IP adresini güncelle
            string mevcutIpAdresi = webYardımcısı.MevcutIpAdresiAl();

            if (!String.IsNullOrEmpty(mevcutIpAdresi))
            {
                var workContext = EngineContext.Current.Resolve <IWorkContext>();
                var kullanıcı   = workContext.MevcutKullanıcı;
                if (!mevcutIpAdresi.Equals(kullanıcı.SonIPAdresi, StringComparison.InvariantCultureIgnoreCase))
                {
                    var kullanıcıServisi = EngineContext.Current.Resolve <IKullanıcıServisi>();
                    kullanıcı.SonIPAdresi = mevcutIpAdresi;
                    kullanıcıServisi.KullanıcıGüncelle(kullanıcı);
                }
            }
        }
Ejemplo n.º 19
0
        public override Task RouteAsync(RouteContext context)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi() || !SeoFriendlyUrlsForLanguagesEnabled)
            {
                return(base.RouteAsync(context));
            }
            var path = context.HttpContext.Request.Path.Value;

            if (!path.IsLocalizedUrl(context.HttpContext.Request.PathBase, false, out Dil _))
            {
                return(base.RouteAsync(context));
            }

            var newPath = path.RemoveLanguageSeoCodeFromUrl(context.HttpContext.Request.PathBase, false);

            context.HttpContext.Request.Path = newPath;
            base.RouteAsync(context).Wait();

            context.HttpContext.Request.Path = path;
            return(_target.RouteAsync(context));
        }
Ejemplo n.º 20
0
        protected void SetWorkingCulture(IWebYardımcısı webHelper, IWorkContext workContext)
        {
            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            var adminAreaUrl = $"{webHelper.SiteKonumuAl()}admin";

            if (webHelper.SayfanınUrlsiniAl(false).StartsWith(adminAreaUrl, StringComparison.InvariantCultureIgnoreCase))
            {
                GenelYardımcı.TelerikKültürAyarla();
                workContext.Yönetici = true;
            }
            else
            {
                var culture = new CultureInfo(workContext.MevcutDil.DilKültürü);
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;
            }
        }
Ejemplo n.º 21
0
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }

                if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
                {
                    return;
                }

                var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
                var actionName       = actionDescriptor?.ActionName;
                var controllerName   = actionDescriptor?.ControllerName;

                if (string.IsNullOrEmpty(actionName) || string.IsNullOrEmpty(controllerName))
                {
                    return;
                }

                //don't validate on ChangePassword page
                if (!(controllerName.Equals("Kullanıcı", StringComparison.InvariantCultureIgnoreCase) &&
                      actionName.Equals("ParolaDeğiştir", StringComparison.InvariantCultureIgnoreCase)))
                {
                    //check password expiration
                    if (_workContext.MevcutKullanıcı.ŞifreKurtarmaLinkiSüresiDoldu())
                    {
                        var changePasswordUrl = _urlHelperFactory.GetUrlHelper(context).RouteUrl("KullanıcıParolaDeğiştirdi");
                        context.Result = new RedirectResult(changePasswordUrl);
                    }
                }
            }
Ejemplo n.º 22
0
        public override VirtualPathData GetVirtualPath(VirtualPathContext context)
        {
            var data = base.GetVirtualPath(context);

            if (data == null)
            {
                return(null);
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi() || !SeoFriendlyUrlsForLanguagesEnabled)
            {
                return(data);
            }

            var path = context.HttpContext.Request.Path.Value;

            if (path.IsLocalizedUrl(context.HttpContext.Request.PathBase, false, out Dil language))
            {
                data.VirtualPath = $"/{language.ÖzelSeoKodu}{data.VirtualPath}";
            }

            return(data);
        }
Ejemplo n.º 23
0
        protected void LogException(Exception exc)
        {
            if (exc == null)
            {
                return;
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }

            //ignore 404 HTTP errors
            var httpException = exc as HttpException;

            if (httpException != null && httpException.GetHttpCode() == 404 &&
                !EngineContext.Current.Resolve <GenelAyarlar>().Günlük404Hataları)
            {
                return;
            }

            try
            {
                //log

                /*
                 * var logger = EngineContext.Current.Resolve<ILogger>();
                 * var workContext = EngineContext.Current.Resolve<IWorkContext>();
                 * logger.Error(exc.Message, exc, workContext.CurrentCustomer);
                 */
            }
            catch (Exception)
            {
                //don't throw new exception if occurs
            }
        }
Ejemplo n.º 24
0
        public virtual void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            //child metod ise gerekli değil
            if (filterContext.IsChildAction)
            {
                return;
            }

            // sadece GET isteklerinde yönlendir,
            // diğer türlü çalışmayacaktır.
            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (!DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                return;
            }
            var güvenlikAyarları = EngineContext.Current.Resolve <GüvenlikAyarları>();

            if (güvenlikAyarları.TümSayfalarıSslİçinZorla)
            {
                //belirtilen değerden bağımsız olarak tüm sayfalar SSL olmaya zorlanır
                this.SslGerekli = SslGerekli.Evet;
            }

            switch (this.SslGerekli)
            {
            case SslGerekli.Evet:
            {
                var webYardımcısı         = EngineContext.Current.Resolve <IWebYardımcısı>();
                var mevcutBağlantıGüvenli = webYardımcısı.MevcutBağlantıGüvenli();
                if (!mevcutBağlantıGüvenli)
                {
                    var siteContext = EngineContext.Current.Resolve <ISiteContext>();
                    if (siteContext.MevcutSite.SslEtkin)
                    {
                        //sayfayı HTTPS sürümüne yönlendir
                        string url = webYardımcısı.SayfanınUrlsiniAl(true, true);

                        //301 (permanent) yönlendirme
                        filterContext.Result = new RedirectResult(url, true);
                    }
                }
            }
            break;

            case SslGerekli.Hayır:
            {
                var webYardımcısı         = EngineContext.Current.Resolve <IWebYardımcısı>();
                var mevcutBağlantıGüvenli = webYardımcısı.MevcutBağlantıGüvenli();
                if (mevcutBağlantıGüvenli)
                {
                    //sayfayı HTTPS sürümüne yönlendir
                    string url = webYardımcısı.SayfanınUrlsiniAl(true, false);
                    //301 (permanent) yönlendirme
                    filterContext.Result = new RedirectResult(url, true);
                }
            }
            break;

            case SslGerekli.ÖnemliDeğil:
            {
                //bişey yapma
            }
            break;

            default:
                throw new TSHata("Desteklenmeyen Ssl Koruma parametresi");
            }
        }
Ejemplo n.º 25
0
        public string SiteHostAl(bool SslKullan)
        {
            var sonuç    = "";
            var httpHost = ServerDeğişkenleri("HTTP_HOST");

            if (!String.IsNullOrEmpty(httpHost))
            {
                sonuç = "http://" + httpHost;
                if (!sonuç.EndsWith("/"))
                {
                    sonuç += "/";
                }
            }

            if (DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                #region Database yüklendi

                //let's resolve IWorkContext  here.
                //Do not inject it via constructor  because it'll cause circular references
                var siteContext = EngineContext.Current.Resolve <ISiteContext>();
                var mevcutSite  = siteContext.MevcutSite;
                if (mevcutSite == null)
                {
                    throw new Exception("Mevcut site yüklenemedi");
                }

                if (String.IsNullOrWhiteSpace(httpHost))
                {
                    //HTTP_HOST değişkeni erişilemez durumda
                    //Bu senaryo, yalnızca HttpContext kullanılabilir olmadığında (örneğin, bir zamanlama görevinde çalışırken) mümkündür.
                    //Bu durumda yönetici alanında yapılandırılmış bir site öğesinin URL'sini kullanın
                    sonuç = mevcutSite.Url;
                    if (!sonuç.EndsWith("/"))
                    {
                        sonuç += "/";
                    }
                }

                if (SslKullan)
                {
                    sonuç = !String.IsNullOrWhiteSpace(mevcutSite.GüvenliUrl) ?
                            mevcutSite.GüvenliUrl :
                            sonuç.Replace("http:/", "https:/");
                }
                else
                {
                    if (mevcutSite.SslEtkin && !String.IsNullOrWhiteSpace(mevcutSite.GüvenliUrl))
                    {
                        sonuç = mevcutSite.Url;
                    }
                }
                #endregion
            }
            else
            {
                #region Database yüklenmedi
                if (SslKullan)
                {
                    sonuç = sonuç.Replace("http:/", "https:/");
                }
                #endregion
            }


            if (!sonuç.EndsWith("/"))
            {
                sonuç += "/";
            }
            return(sonuç.ToLowerInvariant());
        }
Ejemplo n.º 26
0
        public void Configure(IApplicationBuilder application)
        {
            var nopConfig = EngineContext.Current.Resolve <Config>();

            if (nopConfig.UseResponseCompression)
            {
                application.UseResponseCompression();
                application.UseMiddleware <ResponseCompressionVaryWorkaroundMiddleware>();
            }

            application.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    if (!string.IsNullOrEmpty(nopConfig.StaticFilesCacheControl))
                    {
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, nopConfig.StaticFilesCacheControl);
                    }
                }
            });
            //themes
            application.UseStaticFiles(new StaticFileOptions
            {
                FileProvider      = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Temalar")),
                RequestPath       = new PathString("/Temalar"),
                OnPrepareResponse = ctx =>
                {
                    if (!string.IsNullOrEmpty(nopConfig.StaticFilesCacheControl))
                    {
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, nopConfig.StaticFilesCacheControl);
                    }
                }
            });

            //plugins
            var staticFileOptions = new StaticFileOptions
            {
                FileProvider      = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Eklentiler")),
                RequestPath       = new PathString("/Eklentiler"),
                OnPrepareResponse = ctx =>
                {
                    if (!string.IsNullOrEmpty(nopConfig.StaticFilesCacheControl))
                    {
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl,
                                                            nopConfig.StaticFilesCacheControl);
                    }
                }
            };

            //whether database is installed
            if (DataAyarlarıYardımcısı.DatabaseYüklendi())
            {
                var securitySettings = EngineContext.Current.Resolve <GüvenlikAyarları>();
                if (!string.IsNullOrEmpty(securitySettings.EklentiUzantılarıKaraListesi))
                {
                    var fileExtensionContentTypeProvider = new FileExtensionContentTypeProvider();

                    foreach (var ext in securitySettings.EklentiUzantılarıKaraListesi
                             .Split(';', ',')
                             .Select(e => e.Trim().ToLower())
                             .Select(e => $"{(e.StartsWith(".") ? string.Empty : ".")}{e}")
                             .Where(fileExtensionContentTypeProvider.Mappings.ContainsKey))
                    {
                        fileExtensionContentTypeProvider.Mappings.Remove(ext);
                    }

                    staticFileOptions.ContentTypeProvider = fileExtensionContentTypeProvider;
                }
            }
            application.UseStaticFiles(staticFileOptions);

            var provider = new FileExtensionContentTypeProvider();

            provider.Mappings[".bak"] = MimeTipleri.ApplicationOctetStream;
            application.UseStaticFiles(new StaticFileOptions
            {
                FileProvider        = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "db_backups")),
                RequestPath         = new PathString("/db_backups"),
                ContentTypeProvider = provider
            });

            application.UseKeepAlive();
            application.UseInstallUrl();
            application.UseSession();
            application.UseRequestLocalization();
        }