Skip to content

How should I get redirect url for a given url in code? #133

Answered by jaandrews
jaandrews asked this question in Q&A
Discussion options

You must be logged in to vote

@D-Inventor Thanks for the input. I was able to figure out the problem. I was using the intercept service you suggested, but wasn't getting the expected redirect response. Turns out the problem was that the redirect was entered as a relative url, and it needed to be an absolute url since umbraco had a full domain set for its hostname. Below is my code for anyone else that tries to implement this.

public async Task<Models.Redirect> GetRedirect(string url) {
    var uri = new Uri(url);
    var requestUrl = Url.Create(Protocol.Https, uri.Host, uri.Host != "localhost" ? null : uri.Port, uri.AbsolutePath, uri.Query);
    if (await _requestFilters.EvaluateCandidateAsync(requestUrl)) {
        var 

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@jaandrews
Comment options

Answer selected by jaandrews
Comment options

You must be logged in to vote
3 replies
@D-Inventor
Comment options

@jaandrews
Comment options

@jaandrews
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants