Web hayataımızda özellikle sosyal paylaşım sitelerinde bir bağlantı paylaşırken sık sık kullandığımız Tiny Url oluşturma olayını yine tinyUrl üzerinden bir api ile kendi web uygulamalarımızda nasıl kullanacğımızı göstermek amacı ile bu makale ve uygulamayı hazırlayıp paylaşmak istedim.
Aspx Sayfamız
Default.aspx
<head id="Head1" runat="server"> <title></title> </head> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table> <tr> <td> <asp:TextBox ID="txtUrl" runat="server" Height="26px" Width="300px"></asp:TextBox> </td> <td> <asp:Button ID="btnOlustur" runat="server" onclick="btnOlustur_Click" Text="OLUŞTUR" /> </td> </tr> <tr> <td align="right"> <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> <img src="images/loader.gif" /> </ProgressTemplate> </asp:UpdateProgress> </td> <td> &ampnbsp</td> </tr> <tr> <td> <asp:Label ID="lblTinyUrl" runat="server"></asp:Label> </td> <td> <asp:LinkButton ID="lkGit" runat="server" onclick="lkGit_Click"></asp:LinkButton> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> |
C# Kodlarımız
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnOlustur_Click(object sender, EventArgs e) { lblTinyUrl.Text = GetTinyUrl(txtUrl.Text.ToString()); lkGit.Text = GetTinyUrl(txtUrl.Text.ToString()); } public string GetTinyUrl(string urlToMakeTiny) { if (!urlToMakeTiny.ToLower().StartsWith("http://")) { urlToMakeTiny = "http://" + urlToMakeTiny; } //if (urlToMakeTiny.Length < 26) //{ // return urlToMakeTiny; //} return new WebClient().DownloadString("http://tinyurl.com/api-create.php?url=" + urlToMakeTiny); } protected void lkGit_Click(object sender, EventArgs e) { Response.Redirect(lkGit.Text.ToString()); } } |
Uygulamanın Çalışır Haldeki Dosyalarının Tamamını buradan indirebilirsiniz