Revision: 40538
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 3, 2011 09:46 by lance
Initial Code
System.Net.WebClient myClient = new System.Net.WebClient();
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)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
String str = enc.GetString(input);
return str;
}
Initial URL
Initial Description
Initial Title
Screen scrape to get HTML page from client and send to database as binary-return again
Initial Tags
Initial Language
C#