We create a uniquely named request for an image (jpg), and we need to redirect it and collect what its requested name was. We tried doing this in Global.asax and it works great in Dev, but in production it seem to not fire.
It has to be an image (request ends in jpg) or some processors between us an the client will strip the request out. This runs in a virtual directory that does very little other than these image requests. MVC is not an option.
Ex. request = domain/Copyright_123456789.jpg
response = domain/images/Copyright.jpg
collect = 123456789 and place in database
Code
void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.AppRelativeCurrentExecutionFilePath.Contains("Copyright_") && Request.AppRelativeCurrentExecutionFilePath.Contains(".jpg"))
{
int ADFID = 0;
string[] ImageNameArray = Request.AppRelativeCurrentExecutionFilePath.Split(new char[] { '_', '.' });
if (int.TryParse(ImageNameArray[1], out ADFID))
{
QueriesTableAdapter SaveView = new QueriesTableAdapter();
SaveView.FirstQuote_Operations_ClientLeadEmailViews_Save(ADFID);
}
HttpContext.Current.RewritePath("~/images/Copyright.jpg");
}
}
Any help would be much appreciated, thanks.
Here is how I accomplished this. The image src=”website/this virtual directory/Copyright_12345.jpg”
12345 is the value we collect, and we respond with a real jpg on our site
web.config
The tracker class
This is the only class in the website. Create a virtual Directory in IIS for this to live.
Once created, got properties, virtual directory, configuration, mapping. Under Application Extensions hit Add. Enter .jgp, your .NET version isapii (copy it from most any other extension in the window), and set the Verb to All. MAKE SURE TO UNCHECK VERIFY FILE at the bottom.
That should do it.