Skip to main content
Home Forums General Silverlight Hosting and Streaming why my httpmodule rewrite iamge path wroks right at debug, but failed after published?
8 replies. Latest Post by kkdhf on June 27, 2009.
(0)
kkdhf
Member
3 points
32 Posts
06-15-2009 3:47 AM |
why my httpmodule rewrite iamge path wroks right at debug, but failed after published?
follow is the code:
public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); }
void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; if (IsIMG(context.Request.Url.LocalPath) == true) { if (context.Request.Url.LocalPath.EndsWith("NoImage.jpg") == false) { if (File.Exists(context.Server.MapPath(context.Request.Url.LocalPath)) == false) { context.RewritePath("~/NoImage.jpg"); } } } }
06-15-2009 3:59 AM |
...may be i should say more clear. i want to rewrite image path if the server doesn't exist the image.
and the result is when i debug it . it can get a right image if it's not exist.
but at server , seems it passed my code, but nothing happend.
what makes it not works at server? what should i do to make it works like what i want?
can u help me?
tranduybien
186 points
53 Posts
06-15-2009 4:01 AM |
using try catch then MessageBox your error :)
06-15-2009 4:05 AM |
Check UriKind and change to UriKind.RelativeOrAbsolute in IsIMG function
06-15-2009 4:13 AM |
i have added try catch block,and catch nothing.seems it not occurs any exception.
and i use rewritepath("~/noimage.jpg"), i think it will works right , i often used it like this.
i have another module in the same website, it used it , works fine.
hope your reply . :)
06-15-2009 4:26 AM |
try this one: if (context.Request.Url.LocalPath.ToUpterCase().EndsWith("NOIMAGE.JPG") == false)
MessageBox.Show(context.Request.Url.LocalPath); to check valid link
06-15-2009 4:31 AM |
in fact , IsIMG is follow:
private bool IsIMG(string url) { url = url.ToLower(); string con = "(.gif|.bmp|.png|.jpg|.jpeg)$"; Regex regex = new Regex(con); return regex.IsMatch(url); }
and it seems filter other link.
06-15-2009 4:56 AM |
Try to check with :
try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ImageUrl); request.Timeout = 5000; // 5 seconds in milliseconds request.ReadWriteTimeout = 20000; // allow up to 20 seconds to elapse HttpWebResponse response = (HttpWebResponse)request.GetResponse(); return response.GetResponseStream(); } catch { return null; }
06-27-2009 4:04 AM |
in fact , i tried to return Image Bytes to response stream , but always failed at client. i think ,maybe IIS give a 404 error before i rewrite the image path. at last, i add javascript code at every place needed. ... ...