I have a question on StackOverflow, but I thought I'd add it here as well.
http://stackoverflow.com/questions/23505163/composite-c1-how-do-i-redirect-to-a-404-within-an-inlinemethodfunction?noredirect=1#comment36049283_23505163
I have a Composite site where the URL structure is like so:
site.com/products/1234/product-name
The bold part is the page location. 1234 is the Product ID and then product-name is just a slug.
I register PathInfo and I'm using 1234 to read a SQL Database and return information to show on the site. I'm doing that inside an inline C# function called productDetails which returns an XElement to the XSLT Function.
Sometimes, we will discontinue a product or the ID will not exist in our database. What I'd like to do in those cases is to do one of the following
Return a 404
Redirect to my 404 with a URL
I then want to email out a notice (or at least log the error).
Currently, if the product doesn't exist, I just return an empty <product> element.
I have tried the following code inside the InlineMethodFunction > 'productDetails method, but the Response Object doesn't seem to be available. IDEALLY I want to set the Response Type to 404 instead of redirect. Any ideas?:
http://stackoverflow.com/questions/23505163/composite-c1-how-do-i-redirect-to-a-404-within-an-inlinemethodfunction?noredirect=1#comment36049283_23505163
I have a Composite site where the URL structure is like so:
site.com/products/1234/product-name
The bold part is the page location. 1234 is the Product ID and then product-name is just a slug.
I register PathInfo and I'm using 1234 to read a SQL Database and return information to show on the site. I'm doing that inside an inline C# function called productDetails which returns an XElement to the XSLT Function.
Sometimes, we will discontinue a product or the ID will not exist in our database. What I'd like to do in those cases is to do one of the following
Return a 404
Redirect to my 404 with a URL
I then want to email out a notice (or at least log the error).
Currently, if the product doesn't exist, I just return an empty <product> element.
I have tried the following code inside the InlineMethodFunction > 'productDetails method, but the Response Object doesn't seem to be available. IDEALLY I want to set the Response Type to 404 instead of redirect. Any ideas?:
public static class InlineMethodFunction
{
public static XElement productDetails( int BulkProductId ) {
ProductContext db = new ProductContext();
var products = db.ProductDetailsByBulkID(BulkProductId).ToList();
if (products.Count < 1)
{
// THIS doesn't work
Response.Redirect("~/404?ProductCode=" + BulkProductId.ToString());
HttpContext.Current.Response.Redirect("~/404?ProductCode=" + BulkProductId.ToString());
// ERROR RETURNED The name 'HttpContext' does not exist in the current context
}
//
// rest of code
//
}
}