c# - Executing an ASPX file on an ASP.NET MVC Web Application -
i'm going try best explain situation here.
in work, had our whole website using basic asp.net, , kind of created our whole own custom mvc framework scratch, creating our own httpmodules
, , httphandlers
.
this because time, mvc did not exist (at least here), we're talking 12 years ago approximately.
we tried move on, , try upgrade our current project site new asp.net mvc 5 technology. managed make work (apparently), , @ same time keep our legacy business logic untouched.
our business requirements led make route every possible request in our application, , includes static files requests.
we included catch-all route our static requests. route delegate request our custom staticresourcehttphandler
, , processrequest
method executed:
public void processrequest(httpcontext context) { string file = routedata.values["file"].tostring(); string basepath = getbasepath(); string fullpath = path.combine(basepath, file); var extension = file.split(new string[] { "." }, stringsplitoptions.none).last(); context.response.clear(); if(file.exists(fullpath) { context.response.contenttype = getcontenttype(extension.tolower()); using (filestream stream = file.openread(fullpath)) stream.copyto(context.response.outputstream); } else context.response.statuscode = (int)httpstatuscode.notfound; }
as can see, our processrequest
check if file exists in our file system, , if exists returns file's content along correct content-type
header, , http status code of 200 ok
.
this worked far, until now.
we o n process of deploying our web application. configured on iis when 404 encountered, redirect error page made.
our error page static aspx
file.
in our aspx
, have following lines @ beggining:
<% response.status = "404 not found" response.statuscode = 404 %>
with this, make sure 404 not found
status code sent along error page, , not 200 ok
.
the problem our custom static http handler, not execute aspx
. in fact, outputs content of it, status code of 200 ok
, told in code.
how can solve this? how can make code in aspx
file executed? can executed programatically? if so, how can this?
what can done?
preface: have no experience mvc, have experience asp.net.
the problem redirect through iis not same redirect through web.config in application. basically, redirect through iis changes type of request normal request instead of 404 request, swallowing 404 error.
how can handle 404 in asp.net mvc? explains how handle 404 errors in mvc in more detail can.
short explanation: depending on how want use this, choose 1:
- use application_error() handler;
- add special controller 404 errors additional view;
- add customerrors section web.config;
- manually send user error page in endrequest() handler.
as have no experience mvc, cannot in conscience recommend 1 of these 4 methods best or worst method. suggest read answers (in above link) , see 1 works best you.
also, don't understand why you're going mvc, not go way include error page view well.
Comments
Post a Comment