private EmbeddedResourceVirtualFile GetOrCreateVirtualFile(Url url, bool throwOnError)
        {
            // If we're in an application in a folder (i.e. /blog) then remove that part.
            Url testUrl = new Url(VirtualPathUtility.ToAppRelative(url.Path).TrimStart('~'));

            // Always deal with lower-case URLs for aspx pages.
            if (testUrl.Extension == ".aspx")
                testUrl = testUrl.ToString().ToLower();

            // First check if we already have a virtual file cached.
            if (_files.ContainsKey(testUrl))
                return _files[testUrl];

            // Grab the first segment of the path. This will be the assembly prefix.
            string assemblyPathPrefix = testUrl.SegmentAtIndex(0);
            if (string.IsNullOrEmpty(assemblyPathPrefix))
                if (throwOnError)
                    throw new ArgumentException("URL does not contain an assembly path prefix", "url");
                else
                    return null;
            if (!_assemblyPathPrefixes.ContainsKey(assemblyPathPrefix))
                if (throwOnError)
                    throw new ArgumentException("URL does not contain a valid assembly path prefix", "url");
                else
                    return null;

            Assembly assembly = _assemblyPathPrefixes[assemblyPathPrefix];

            // Now get the rest of the path. This, combined with the assembly prefix, will be the resource path.
            Url remainingUrl = testUrl.RemoveSegment(0);
            string resourcePath = remainingUrl.PathWithoutExtension.Replace('/', '.');
            if (remainingUrl.Extension == ".aspx")
            {
                resourcePath = Regex.Replace(resourcePath, "[^a-zA-Z]([a-z])|^([a-z])", m => m.Captures[0].Value.ToUpper());
                resourcePath = Regex.Replace(resourcePath, "-", string.Empty);
            }

            // Create a new virtual file.
            EmbeddedResourceVirtualFile virtualFile = new EmbeddedResourceVirtualFile(url, assembly, assembly.GetName().Name + resourcePath + remainingUrl.Extension);
            _files.Add(testUrl, virtualFile);

            // Check that resource actually exists.
            if (assembly.GetManifestResourceStream(virtualFile.ResourcePath) == null)
                throw new ArgumentException(string.Format("Cannot find resource in assembly '{0}' matching resource path '{1}'.", assembly, virtualFile.ResourcePath));

            return virtualFile;
        }
Beispiel #2
0
        protected virtual void OnEndRequest(object source, EventArgs eventArgs)
        {
            if (!_onEnterCalled)
                return;

            _onEnterCalled = false;

            HttpApplication application = (HttpApplication) source;
            HttpContext context = application.Context;
            if (context.Response.StatusCode != 0x191)
                return;

            // Add new ReturnUrl parameter, which will remove any existing parameter of this name.
            Url redirectUrl = new Url(CurrentAuthenticationService.LoginUrl);
            redirectUrl.SetQueryParameter("ReturnUrl", new Url(context.Request.Url).PathAndQuery);
            context.Response.Redirect(redirectUrl.ToString(), false);
        }