c# - Upgrade to MVC3. ashx resource cannot be found. Routing issue? -
i have searched high , low solution problem , have not found one. upgraded mvc2 application mvc3 using guide: http://www.asp.net/whitepapers/mvc3-release-notes#upgrading
i upgraded project vs2008 vs2012. iis 7.5
everything went flawlessly except preview.ashx giving me resource not found. page supposed display preview image when called url in query string. tried changing routes, checking controller names, setting specific page
in web
settings, etc. pretty sure has routes or setting got screwed during upgrade, cannot figure out.
i have site setup using virtual directory in iis @ http://localhost/comm
edit: rebuilt site using fresh installation of mvc3 , problem still exists. after rebuilding site realized there .aspx files in same directory work fine. .ashx files not routing correctly.
global.asax
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.ignoreroute("{resource}.aspx/{*pathinfo}"); routes.ignoreroute("{resource}.ashx/{*pathinfo}"); routes.maproute( "default", // route name "{instance}/{controller}/{action}/{id}", // url parameters new { instance = "demo", controller = "home", action = "index", id = urlparameter.optional } // parameter defaults ); } protected void application_start() { arearegistration.registerallareas(); registerroutes(routetable.routes); }
error
the resource cannot found. description: http 404. resource looking (or 1 of dependencies) have been removed, had name changed, or temporarily unavailable. please review following url , make sure spelled correctly. requested url: /comm/views/review/fileviewer.ashx
i gave trying ashx
work , ended building filesresult
action in controller returns image. ashx
receiving httpcontext
in order process image , return it. created action takes path, performs work, , returns image. there wonky .ashx
files , mvc routing not figure out. none of ashx
files working, can rebuilt actions guess not big deal. below action replaces preview.ashx
public fileresult preview(string path) { // database fetch of image details try { // relative path if (!path.isnull()) { // path string filepath = path; string absolutepath = ... // make sure the file exists if (system.io.file.exists(absolutepath)) { // check preview string previewpath = ...; // has preview bool haspreview = true; // check see if preview exists if (!system.io.file.exists(previewpath) || system.io.file.getlastwritetime(previewpath) < system.io.file.getlastwritetime(absolutepath)) { try { // generate preview haspreview = ... != null; } catch (exception exc) { haspreview = false; } } // once path handled, set type if (haspreview) { return new filestreamresult(new filestream(previewpath, filemode.open), "image/png"); } // no preview else return writedefault(); } else // write default (blank) return writedefault(); } else { return writedefault(); } } catch { // write default (no_photo) return writedefault(); } } private filecontentresult writedefault() { // write default system.drawing.bitmap bmp = new bitmap(25, 25); system.drawing.graphics g = system.drawing.graphics.fromimage(bmp); g.interpolationmode = system.drawing.drawing2d.interpolationmode.highqualitybicubic; g.fillrectangle(system.drawing.brushes.white, 0, 0, 25, 25); bmp = new bitmap(25, 25, g); memorystream str = new memorystream(); bmp.save(str, imageformat.png); return file(str.toarray(), "image/png"); }
Comments
Post a Comment