Menu

#4 404 Redirect fixes

v1.0 (example)
open
nobody
None
5
2014-09-03
2014-08-18
No

Hi,

thanks for URL Shortener, I have made a few changes to get it working using 404 redirect.

1.) ShortURL.Utils

InternalShortURL, replacing domain does not actually clean up the string enough. this just gets the last part of the string after the last "/"

public static string InternalShortUrl(string short_url)
{
int position = short_url.LastIndexOf('/');
if (position != -1)
{
return short_url.Substring(position + 1);
} else
{
return String.Empty;
}
}

2.) Redirection.ASPX.cs

I removed code in regards to "(ShortUrl.Utils.HasValue(Request.QueryString["page"].ToString())) // checks in case ISAPIRewrite is being used" because it contains an error.

protected void Page_Load(object sender, EventArgs e)
{
ShortUrl.Container oShortUrl;

    oShortUrl = ShortUrl.Utils.RetrieveUrlFromDatabase(ShortUrl.Utils.InternalShortUrl(Request.Url.ToString()));


    if (oShortUrl.RealUrl != null)
    {
        Response.Redirect(oShortUrl.RealUrl);
    }
    else
    {
        Response.Redirect("MissingUrl.aspx");
    }
}

Discussion


Log in to post a comment.