Пример #1
0
        protected static void RedirectWithLanguage(
            System.Web.HttpContextBase context,
            string urlNonlocalized,
            string langtag,
            IUrlLocalizer m_urlLocalizer)
        {
            // Construct localized URL.
            string urlNew = m_urlLocalizer.SetLangTagInUrlPath(context, urlNonlocalized, UriKind.Relative, langtag);

            // Redirect user agent to new local URL.
            if (LocalizedApplication.Current.PermanentRedirects)
            {
                context.Response.StatusCode = 301;
                context.Response.Status     = "301 Moved Permanently";
            }
            else
            {
                context.Response.StatusCode = 302;
                context.Response.Status     = "302 Moved Temporarily";
            }
            context.Response.RedirectLocation = urlNew;

            // End the request early: no further processing along the pipeline.
            // NB: we did originally use context.Response.End(); here but that causes an
            // unnecessary exception to be thrown (https://support.microsoft.com/en-us/kb/312629) (#195)
            // NB: the line AFTER this line will execute, so best to return immediately here
            // and from caller etc..
            context.ApplicationInstance.CompleteRequest();
        }
Пример #2
0
 public DefaultRootServices()
 {
     // Use Lazy to delay the creation of objects to when a request is being processed.
     // When initializing the app thehi may throw "Request is not available in this context" from WebConfigService
     translationRepository = new Lazy <POTranslationRepository>(() => new POTranslationRepository(new i18nSettings(new WebConfigSettingService())));
     urlLocalizer          = new UrlLocalizer();
     textLocalizer         = new Lazy <TextLocalizer>(() => new TextLocalizer(new i18nSettings(new WebConfigSettingService()), TranslationRepositoryForApp));
     earlyUrlLocalizer     = new EarlyUrlLocalizer(urlLocalizer);
     nuggetLocalizer       = new Lazy <NuggetLocalizer>(() => new NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), TextLocalizerForApp));
 }
Пример #3
0
 public DefaultRootServices()
 {
     // Use Lazy to delay the creation of objects to when a request is being processed.
     // When initializing the app thehi may throw "Request is not available in this context" from WebConfigService 
     translationRepository = new Lazy<POTranslationRepository>(() => new POTranslationRepository(new i18nSettings(new WebConfigSettingService())));
     urlLocalizer = new UrlLocalizer();
     textLocalizer = new Lazy<TextLocalizer>(() => new TextLocalizer(new i18nSettings(new WebConfigSettingService()), TranslationRepositoryForApp));
     earlyUrlLocalizer = new EarlyUrlLocalizer(urlLocalizer);
     nuggetLocalizer = new Lazy<NuggetLocalizer>(() => new NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), TextLocalizerForApp));
 }
 public UrlUnlocalizationMiddleware(RequestDelegate next, IUrlLocalizer urlLocalizer, UrlUnlocalizationOptions options)
 {
     _next         = next;
     _urlLocalizer = urlLocalizer;
     _options      = options;
 }
Пример #5
0
        protected static void RedirectWithLanguage(
            System.Web.HttpContextBase context, 
            string urlNonlocalized,
            string langtag,
            IUrlLocalizer m_urlLocalizer)
        {
            // Construct localized URL.
            string urlNew = m_urlLocalizer.SetLangTagInUrlPath(context, urlNonlocalized, UriKind.Relative, langtag);

            // Redirect user agent to new local URL.
            if (LocalizedApplication.Current.PermanentRedirects) {
                context.Response.StatusCode = 301;
                context.Response.Status = "301 Moved Permanently";
            }
            else {
                context.Response.StatusCode = 302;
                context.Response.Status = "302 Moved Temporarily";
            }
            context.Response.RedirectLocation = urlNew;

            // End the request early: no further processing along the pipeline.
            // NB: we did originally use context.Response.End(); here but that causes an
            // unnecessary exception to be thrown (https://support.microsoft.com/en-us/kb/312629) (#195)
            // NB: the line AFTER this line will execute, so best to return immediately here
            // and from caller etc..
            context.ApplicationInstance.CompleteRequest();
        }
Пример #6
0
 public EarlyUrlLocalizer(IUrlLocalizer urlLocalizer)
 {
     m_urlLocalizer = urlLocalizer;
 }
Пример #7
0
 public EarlyUrlLocalizer(IUrlLocalizer urlLocalizer)
 {
     m_urlLocalizer = urlLocalizer;
 }
 public UrlLocalizationUrlHelper(IUrlHelper urlHelper, IUrlLocalizer urlLocalizer)
     : base(urlHelper.ActionContext)
 {
     _urlHelper    = urlHelper;
     _urlLocalizer = urlLocalizer;
 }
Пример #9
0
 public UrlLocalizationUrlHelperFactory(IUrlHelperFactory helperFactory, IUrlLocalizer urlLocalizer)
 {
     _helperFactory = helperFactory;
     _urlLocalizer  = urlLocalizer;
 }