I've made a couple of routes for my webform using the global.asax file. When i don't specify a file i want to open, it works just fine, but when i want to route a file, it tries to open as an image and not a page with a file on it. Anyone who has got any
ideas?
Global.asax:
routes.MapPageRoute("PhotographiesRoute", "Photographies/{folder}", "~/Photo/Default.aspx");
routes.MapPageRoute("PhotographiesFileRoute", "Photographies/{folder}/{file}", "~/Photo/Default.aspx");
Default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
string folder = Page.RouteData.Values["folder"] as string;
string file = Page.RouteData.Values["file"] as string;
if(!string.IsNullOrEmpty(file) && !string.IsNullOrEmpty(folder)
displayImage(folder,file); // 'causes errorcode 404.0 Not Found
else if(!string.IsNullOrEmpty(folder)
displayFolder(folder); // works perfectly
else
Response.Redirect("/"); // no problems here either
}
generated links:
http://localhost/Photographies/Nature/
http://localhost/Photographies/Nature/IMG_0001.jpg //this 'causes the problem
Also, if anyone has improvement for the code, that would be nice aswell
Best Regards
Please remember to post your code.
If this post answered your question or solved your problem, please Mark it as Answer.
This is because the routing never sees the file as IIS intercepts the request and serves it directly. You need to tell IIS to run the routing for all requests. In web.config, make sure you have runAllManagedModulesForAllRequests set. Eg:
Trolderik
Member
645 Points
355 Posts
routing file
Apr 09, 2012 06:21 PM|LINK
Hi everyone,
I've made a couple of routes for my webform using the global.asax file. When i don't specify a file i want to open, it works just fine, but when i want to route a file, it tries to open as an image and not a page with a file on it. Anyone who has got any ideas?
Global.asax: routes.MapPageRoute("PhotographiesRoute", "Photographies/{folder}", "~/Photo/Default.aspx"); routes.MapPageRoute("PhotographiesFileRoute", "Photographies/{folder}/{file}", "~/Photo/Default.aspx"); Default.aspx: protected void Page_Load(object sender, EventArgs e) { string folder = Page.RouteData.Values["folder"] as string; string file = Page.RouteData.Values["file"] as string; if(!string.IsNullOrEmpty(file) && !string.IsNullOrEmpty(folder) displayImage(folder,file); // 'causes errorcode 404.0 Not Found else if(!string.IsNullOrEmpty(folder) displayFolder(folder); // works perfectly else Response.Redirect("/"); // no problems here either } generated links: http://localhost/Photographies/Nature/ http://localhost/Photographies/Nature/IMG_0001.jpg //this 'causes the problemAlso, if anyone has improvement for the code, that would be nice aswell
Best Regards
If this post answered your question or solved your problem, please Mark it as Answer.
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: routing file
Apr 10, 2012 08:11 AM|LINK
This is because the routing never sees the file as IIS intercepts the request and serves it directly. You need to tell IIS to run the routing for all requests. In web.config, make sure you have runAllManagedModulesForAllRequests set. Eg:
<div class="line number2 index1 alt1"><system.webServer></div> <div class="line number3 index2 alt2"><modulesrunAllManagedModulesForAllRequests="true"></div> <div class="line number4 index3 alt1"></modules></div></system.webServer>
Trolderik
Member
645 Points
355 Posts
Re: routing file
Apr 10, 2012 01:18 PM|LINK
Thank you very much for your help. That solved my problem like a charm!
If this post answered your question or solved your problem, please Mark it as Answer.