当前位置: 首页>>代码示例>>C#>>正文


C# IHttpResponse.Redirect方法代码示例

本文整理汇总了C#中IHttpResponse.Redirect方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.Redirect方法的具体用法?C# IHttpResponse.Redirect怎么用?C# IHttpResponse.Redirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpResponse的用法示例。


在下文中一共展示了IHttpResponse.Redirect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            var fileName = request.GetPhysicalPath();

            var fi = new FileInfo(fileName);
            if (!fi.Exists)
            {
                if ((fi.Attributes & FileAttributes.Directory) != 0)
                {
                    foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
                    {
                        var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
                        if (!File.Exists(defaultFileName)) continue;
                        response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
                        return;
                    }
                }

                if (!fi.Exists)
                    throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
            }

            TimeSpan maxAge;
            if (response.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(response.ContentType, out maxAge))
            {
                response.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
            }

            if (request.HasNotModifiedSince(fi.LastWriteTime))
            {
                response.ContentType = MimeTypes.GetMimeType(fileName);
                response.StatusCode = 304;
                return;
            }

            try
            {
                response.AddHeaderLastModified(fi.LastWriteTime);
                response.ContentType = MimeTypes.GetMimeType(fileName);

                if (!Env.IsMono)
                {
                    response.TransmitFile(fileName);
                }
                else
                {
                    response.WriteFile(fileName);
                }
            }
            catch (Exception)
            {
                throw new HttpException(403, "Forbidden.");
            }
        }
开发者ID:theouteredge,项目名称:ServiceStack,代码行数:54,代码来源:StaticFileHandler.cs

示例2: Process

        /// <summary>
        /// Process the incoming request.
        /// </summary>
        /// <param name="request">incoming HTTP request</param>
        /// <param name="response">outgoing HTTP response</param>
        /// <returns>true if response should be sent to the browser directly (no other rules or modules will be processed).</returns>
        /// <remarks>
        /// returning true means that no modules will get the request. Returning true is typically being done
        /// for redirects.
        /// </remarks>
        /// <exception cref="ArgumentNullException">If request or response is null</exception>
        public override bool Process(IHttpRequest request, IHttpResponse response)
        {
            if (request == null)
                throw new ArgumentNullException("request");
            if (response == null)
                throw new ArgumentNullException("response");

            // If a match is found
            if (_matchUrl.IsMatch(request.Uri.AbsolutePath))
            {
                // Return the replace result
                string resultUrl = _matchUrl.Replace(request.Uri.AbsolutePath, ToUrl);
                if (!ShouldRedirect)
                {
                    request.Uri = new Uri(request.Uri, resultUrl);
                    return false;
                }

                response.Redirect(resultUrl);
                return true;
            }

            return false;
        }
开发者ID:BGCX261,项目名称:zma-svn-to-git,代码行数:35,代码来源:RegexRedirectRule.cs

示例3: Process

        /// <summary>
        /// Process the incoming request.
        /// </summary>
        /// <param name="request">incoming HTTP request</param>
        /// <param name="response">outgoing HTTP response</param>
        /// <returns>true if response should be sent to the browser directly (no other rules or modules will be processed).</returns>
        /// <remarks>
        /// returning true means that no modules will get the request. Returning true is typically being done
        /// for redirects.
        /// </remarks>
        public virtual bool Process(IHttpRequest request, IHttpResponse response)
        {
            if (request.Uri.AbsolutePath == FromUrl)
            {
                if (!ShouldRedirect)
                {
                    request.Uri = new Uri(request.Uri, ToUrl);
                    return false;
                }

                response.Redirect(ToUrl);
                return true;
            }

            return false;
        }
开发者ID:BGCX261,项目名称:zma-svn-to-git,代码行数:26,代码来源:RedirectRule.cs

示例4: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            var fileName = request.GetPhysicalPath();

            var fi = new FileInfo(fileName);
            if (!fi.Exists)
            {
                if ((fi.Attributes & FileAttributes.Directory) != 0)
                {
                    foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
                    {
                        var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
                        var defaultFileInfo = new FileInfo(defaultFileName);
                        if (!defaultFileInfo.Exists) continue;
                        response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
                        return;
                    }
                }

                if (!fi.Exists)
                    throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
            }

            var strHeader = request.Headers["If-Modified-Since"];
            try
            {
                if (strHeader != null)
                {
                    var dtIfModifiedSince = DateTime.ParseExact(strHeader, "r", null);
                    var ftime = fi.LastWriteTime.ToUniversalTime();
                    if (ftime <= dtIfModifiedSince)
                    {
                        response.ContentType = MimeTypes.GetMimeType(fileName);
                        response.StatusCode = 304;
                        return;
                    }
                }
            }
            catch { }

            try
            {
                var lastWT = fi.LastWriteTime.ToUniversalTime();
                response.AddHeader("Last-Modified", lastWT.ToString("r"));

                response.ContentType = MimeTypes.GetMimeType(fileName);

                if (!Env.IsMono)
                {
                    response.TransmitFile(fileName);
                }
                else
                {
                    response.WriteFile(fileName);
                }
            }
            catch (Exception)
            {
                throw new HttpException(403, "Forbidden.");
            }
        }
开发者ID:Braunson,项目名称:ServiceStack,代码行数:61,代码来源:StaticFileHandler.cs

示例5: GetMeshHandler

        private void GetMeshHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            // TODO: Change this to a config option
            const string REDIRECT_URL = null;

            // Try to parse the mesh ID from the request URL
            NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
            string meshStr = query.GetOne("mesh_id");

            UUID meshID;
            if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID))
            {
                Asset mesh;

                if (!String.IsNullOrEmpty(REDIRECT_URL))
                {
                    // Only try to fetch locally cached meshes. Misses are redirected
                    if (m_assetClient.TryGetCachedAsset(meshID, "application/vnd.ll.mesh", out mesh))
                    {
                        SendMesh(request, response, mesh);
                    }
                    else
                    {
                        string meshUrl = REDIRECT_URL + meshID.ToString();
                        m_log.Debug("Redirecting mesh request to " + meshUrl);
                        response.Redirect(meshUrl);
                    }
                }
                else
                {
                    // Fetch locally or remotely. Misses return a 404
                    if (m_assetClient.TryGetAsset(meshID, "application/vnd.ll.mesh", out mesh))
                    {
                        SendMesh(request, response, mesh);
                    }
                    else
                    {
                        m_log.Warn("Mesh " + meshID + " not found, returning a 404");
                        response.Status = System.Net.HttpStatusCode.NotFound;
                    }
                }
            }
            else
            {
                m_log.Warn("Failed to parse a mesh_id from GetMesh request: " + request.Uri);
            }
        }
开发者ID:thoys,项目名称:simian,代码行数:47,代码来源:GetMesh.cs

示例6: GetTextureHandler

        private void GetTextureHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            // TODO: Change this to a config option
            const string REDIRECT_URL = null;

            // Try to parse the texture ID from the request URL
            NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
            string textureStr = query.GetOne("texture_id");

            UUID textureID;
            if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out textureID))
            {
                Asset texture;

                if (!String.IsNullOrEmpty(REDIRECT_URL))
                {
                    // Only try to fetch locally cached textures. Misses are redirected
                    if (m_assetClient.TryGetCachedAsset(textureID, "image/x-j2c", out texture))
                    {
                        SendTexture(request, response, texture);
                    }
                    else
                    {
                        string textureUrl = REDIRECT_URL + textureID.ToString();
                        m_log.Debug("Redirecting texture request to " + textureUrl);
                        response.Redirect(textureUrl);
                    }
                }
                else
                {
                    // Fetch locally or remotely. Misses return a 404
                    if (m_assetClient.TryGetAsset(textureID, "image/x-j2c", out texture))
                    {
                        SendTexture(request, response, texture);
                    }
                    else
                    {
                        m_log.Warn("Texture " + textureID + " not found");

                        if (m_assetClient.TryGetCachedAsset(MISSING_IMAGE, "image/x-j2c", out texture))
                        {
                            SendTexture(request, response, texture);
                        }
                        else
                        {
                            m_log.Warn("Missing image texture " + MISSING_IMAGE + " not found, returning a 404");
                            response.Status = System.Net.HttpStatusCode.NotFound;
                        }
                    }
                }
            }
            else
            {
                m_log.Warn("Failed to parse a texture_id from GetTexture request: " + request.Uri);
            }
        }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:56,代码来源:GetTexture.cs


注:本文中的IHttpResponse.Redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。