간단한 URL 단축 코드를 코딩하고 있습니다.RedirectPermanent가 URL로 리디렉션되지 않습니다.
리디렉션을 제외한 모든 기능이 작동합니다.
public async Task<ActionResult> Click(string segment)
{
string referer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : string.Empty;
Stat stat = await this._urlManager.Click(segment, referer, Request.UserHostAddress);
return this.RedirectPermanent(stat.ShortUrl.LongUrl);
}
I 입력이 http://localhost:41343/5d8a2a 같은 단축 링크가, 그것은 나를 대신 www.google.com.br의 http://localhost:41343/www.google.com.br로 리디렉션 : 여기
리디렉션하려고 코드입니다.답을 확인한 후 편집
, 그것을 작동합니다. 다음은 코드의 마지막 스 니펫입니다.
if (!stat.ShortUrl.LongUrl.StartsWith("http://") && !stat.ShortUrl.LongUrl.StartsWith("https://"))
return this.RedirectPermanent("http://" + stat.ShortUrl.LongUrl);
else
return this.RedirectPermanent(stat.ShortUrl.LongUrl);
감사합니다.
그리고'무엇을 반환 LongUrl' 않습니다를 추가 할 수 있습니다? –
@DovydasSopa longUrl은 www.google.com –
을 반환합니다. LongUrl에 http : //가 있으면 작동합니다. url에 http : //가 포함되어 있는지 확인하는 대신에 방법이 있습니까? –