System.Runtime.Remoting.Channels.Http.HttpChannelHelper.GetObjectUriFromRequestUri C# (CSharp) Метод

GetObjectUriFromRequestUri() статический приватный Метод

static private GetObjectUriFromRequestUri ( String uri ) : String
uri String
Результат String
        internal static String GetObjectUriFromRequestUri(String uri)
        {
            // We assume uri may be in one of the following forms
            //   http://myhost.com/myobject.rem
            //   /myobject.rem
            //   /myobject
            //   myobject.rem
            // In all cases, myobject is considered to be the object URI (.rem might be absent)

            int start, end; // range of characters to use
            int index;
            start = 0;
            end = uri.Length;

            // first see if uri starts with http://
            // and remove up to next slash if it does
            start = StartsWithHttp(uri);
            if (start != -1)
            {
                // remove domain name as well
                index = uri.IndexOf('/', start);
                if (index != -1)
                    start = index + 1;
                else
                    start = end; // uri will end up being ""
            }
            else
            {
                // remove "/" if this is an absolute path
                start = 0; 
                if (uri[start] == '/')
                   start++;
            }

            // remove query string if present ('?' and everything past it)
            index = uri.IndexOf('?');
            if (index != -1)
                end = index;

            if (start < end)
                return CoreChannel.RemoveApplicationNameFromUri(uri.Substring(start, end - start));
            else
                return "";
        } // GetObjectURIFromRequestURI

Usage Example

        bool CanServiceRequest(HttpContext context)
        {
            //Need to get the object uri first (cannot have query string)
            string requestUri = GetRequestUriForCurrentRequest(context);
            string objectUri  = HttpChannelHelper.GetObjectUriFromRequestUri(requestUri);

            context.Items["__requestUri"] = requestUri;

            if (String.Compare(context.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) != 0)
            {
                //If the request backed by an existing object
                if (RemotingServices.GetServerTypeForUri(requestUri) != null)
                {
                    return(true);
                }
            }
            else
            {
                if (context.Request.QueryString.Count != 1)
                {
                    return(false);
                }

                string[] values = context.Request.QueryString.GetValues(0);
                if (values.Length != 1 || String.Compare(values[0], "wsdl", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(false);
                }

                //If the request specifically asks for the wildcard
                if (String.Compare(objectUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }

                // find last index of ?
                int index = requestUri.LastIndexOf('?');
                if (index != -1)
                {
                    requestUri = requestUri.Substring(0, index);
                }

                //If the request backed by an existing object
                if (RemotingServices.GetServerTypeForUri(requestUri) != null)
                {
                    return(true);
                }
            }

            //If the request is backed by an existing file on disk it should be serviced
            if (File.Exists(context.Request.PhysicalPath))
            {
                return(true);
            }

            return(false);
        }
All Usage Examples Of System.Runtime.Remoting.Channels.Http.HttpChannelHelper::GetObjectUriFromRequestUri