Category

ASP.Net
First test to see if the object is a castable class if that doesn’t work for basic types int string etc then you will use Convert.ChangeType.. if (readData is T) { return (T)readData; } try { return (T)Convert.ChangeType(readData, typeof(T)); } catch (InvalidCastException) { return default(T); }
Read More
public static void CleanExit(string reponseText = null) { if (String.IsNullOrEmpty(reponseText) == false) { HttpContext.Current.Response.Write(reponseText); } try { //Sends the response buffer HttpContext.Current.Response.Flush(); // Prevents any other content from being sent to the browser HttpContext.Current.Response.SuppressContent = true; //Directs the thread to finish, bypassing additional processing HttpContext.Current.ApplicationInstance.CompleteRequest(); //Suspends the current thread Thread.Sleep(1); } catch { } finally...
Read More
//Full URL string url = HttpContext.Current.Request.Url.ToString(); // http://localhost:1234/test/test.aspx?cool=true string url = HttpContext.Current.Request.Url.AbsoluteUri; // http://localhost:1234/test/test.aspx string path = HttpContext.Current.Request.Url.AbsolutePath; // /test/test.aspx string host = HttpContext.Current.Request.Url.Host; // localhost Here it is in a function: public enum URLType { Full, URI, Path, Host } public static string GetCurrentURL(URLType type = URLType.Full) { switch (type) { case URLType.URI: return...
Read More