/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
byte[] requestHTML; //setup credentials to do the double hop between the server and client System.Security.Principal.WindowsImpersonationContext impersonationContext = default(System.Security.Principal.WindowsImpersonationContext); System.Security.Principal.WindowsIdentity currentIdentity = (System.Security.Principal.WindowsIdentity)User.Identity; impersonationContext = currentIdentity.Impersonate(); myClient.Credentials = System.Net.CredentialCache.DefaultCredentials; requestHTML = myClient.DownloadData(Request.Url.ToString()); int pageID = bis.IntInsertPage(appraisalID, requestHTML);//Insert the page in the database and get the pageID // Revert back to original context of the ASP.NET process impersonationContext.Undo(); DbCommand command = dbSQL.GetStoredProcCommand("dbo.procInsertPage"); dbSQL.AddInParameter(command, "AppraisalID", DbType.Int32, appraisalID); dbSQL.AddInParameter(command, "Page", DbType.Binary, page); dbSQL.AddOutParameter(command, "PageID", DbType.Int32, 4); try { dbSQL.ExecuteNonQuery(command); return Convert.ToInt32(dbSQL.GetParameterValue(command, "@PageID")); } //return binary data so we can display //convert the binary back to a string containing the original HTML string htmlPage = ConvertBinaryToString((byte[])page); //decode the page string decHtmlPage = Server.HtmlDecode(htmlPage); // display the retrieved page in a literal control litPage.Text = decHtmlPage; //Method to convert binary to string protected string ConvertBinaryToString(Byte[] input) { String str = enc.GetString(input); return str; }