How do I get the Controller and Action names from the Referrer Uri?

前端 未结 9 1056
清歌不尽
清歌不尽 2020-12-01 14:06

There\'s a lot of information for building Uris from Controller and Action names, but how can I do this the other way around?

Basically, all I\'m trying to achieve i

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 14:29

    This is a method I made to extract url simplified from referrer because I had token (finished with "))/") in my URL so you can extract easily controller and action from this:

    private static string GetURLSimplified(string url)
        {
            string separator = "))/";
            string callerURL = "";
    
            if (url.Length > 3)
            {
                int index = url.IndexOf(separator);
                callerURL = url.Substring(index + separator.Length);
            }
            return callerURL;
        }
    

提交回复
热议问题