ASP.NET HttpHandler and WebResource.axd issues - asp.net

I need a simple HttpHandler to handle specific non-existant paths in my ASP.NET project. I'm using sitefinity 4. I wrote the handler but whenever I try to run the site, I get a frustrating error
The WebResource.axd handler must be registered in the configuration to process this request.
I was putting the handler in the system.web part of the config but it looks liek VS2010 still uses IIS 6 for it's built in web server so I went ahead and switched it to use IIS 7 (local) and moved the registration of the handler to system.webServer and it works when I hit a non existant url but if I try to go to the site normally (valid url) I get that dang error again.
It worked once, giving me the correct site on a valid url but now it just continues to give me trouble.
How can I resolve this issue? I don't want to add that entry to the config as it wasn't there when I created the project and it only started when I added my handler.
EDIT: Only happens when I use Path="*" so how do I do a wildcard? I don't want to map a handler to catch a 404 page.

Froget it. No one seems to know even though I know i'm not the only one who has needed to do this. I got 404 to work but ONLY when I request a file, not a folder so thats a bust.
I found that Global.asax will hit under integrated mode so I just moved my code to the Application_BeginRequest() and it's working just fine. If anyone else has a better answer I will give them credit.

for iis7 and iis7.5, handlers are registered in system.webserver. the httphandlers and httpmodules in system.web are ignored and are used for IIS 6 and classic mode.
i hope this was helpful!

Related

How to override page render for an error page?

We have an ASP.NET MVC application, and when it encounters an error you are not redirected to an erro rpage, instead the content of that page is replaced with the content of the error page. You go fix your code and press refresh and you're done.
We have another application that's written in WebForms and I'd like to get the same behavior out of it. Right now the current behavior is that when an error occurs you get redirected to ~/Error.aspx. Is it possible to make webforms behave this way? Perhaps override the page render event somehow?
This is just for development right? Displaying the error.aspx on production is much better both from a security and user experience perspective.
In order to turn off custom errors, you need to know how to turn them on. Yes? There are several places custom errors can be configured.
in IIS Create a Custom HTTP Error Response (IIS 7)
an error handler on the page, in global.asax, or in a class defined elsewhere (app_code folder perhaps)
in web.config Web.config customErrors mode
Web.config is probably the most common place. Start there.

Asp.net Application_BeginRequest not fired, global.asax not run at server

For URL rewriting i have written code in global.asax
for just testing simply i'm trying to
string hurl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower()
if(hurl.Contains("atech.html")){HttpContext.Current.RewritePath("btech.html");}
i have also configure
<modules runAllManagedModulesForAllRequests="true"/>
this works in my local iis but i not run at my hosting server
giving 404 error.
Try switch Managed Pipeline Mode from classic to integrated in Application pool
OK so here is the way I fixed this... IIS needs to be told which files to handle. In my case I needed some handlers for *.js files and *.php files to redirect to an aspx or ashx files.
Locally it works just fine but when i deploy all i get is 404's.
So you need to go into IIS. Find your site configuration and add entries in your Handler Mappings (IIS7, in IIS6 I think its in Application configuration) to handle *.XXX and have whatever handler you have for *.aspx handle it (usually its System.Web.UI.PageHandlerFactory)
And it should be fixed. Hope this helps
I was able to fix this problem by publishing my web site using the option "delete all existing files prior to publishing", this option is located on the Publish wizard window, "Settings" > "File publish options".
In my case, for some unknown reason, execution of Application_BeginRequest on global.asax.cs was being ignored, I was able to confirm this problem adding a log entry within Application_BeginRequest, the log entry was never recorded.

How to redirect a exception to a custom page in IIS 6 for a website which I don't have access to the source code|

I have a asp.net website hosted in IIS 5 and i don't have access to the source code, but i do have access to server. What i need is a server level way to redirect the user to a custom error page when an exception of the type "SecurityException" occurrs.
Since I can't use it via global asax i was wondering if i could use elmah to catch the error and redirect it to a specific url instead of logging/mailing it.
I'm open to alternatives too.. so if someone knows a trick to do this using a different approach I would appreciated very much.
Thanks!
Best regards,
byte_slave
ELMAH logs exceptions for you. It will not redirect to a particular page. ELMAH is configured in Web.Config which you do have access to.
You can also setup a custom error page in Web.Config.
<customErrors defaultRedirect="url" mode="On">
<error redirect="PlaceYourUrlHere"/>
</customErrors>
BTW, I had a similar situation once (a laptop with source was stolen). I took the binaries off the server and decompiled them. You can try using JustDecompile, Reflector,
Here is another SO question with some more decompile alternatives: A .net disassembler/decompiler
Once you have decompiled the binaries you can put back together the project and solution files. Of course assuming the binaries are not obfuscated or encrypted in some manner. But this is rarely done for web apps, so I would give it a shot.
Ok. So the way i fix this, was downloading and compiling a ELMAH source code, with a very small change in the code to catch the desired exceptions and then it redirects to the address I want.

CustomErrors only catches explicit page links

I have custom errors turned on and when I go to
www.mywebsite.com/video/default.aspx it shows error which corresponds to 404 and this is fine
but when I go to www.mywebsite.com/video/ it shows a generic iis 404 error.
My other pages that have files work fine like
www.mywebsite.com/photo/ would redirect to www.mywebsite.com/photo/default.aspx because files exists and default is setup in IIS.
Please help. Thanks!
The 404 handler specified in the web.config only works for files handled by the ASP.NET runtime. This is why it is working for www.mywebsite.com/video/default.aspx and not www.mywebsite.com/video/, the generic error your observing is the one configured by default in IIS. You will need to go into IIS Manager and set 404's to be redirected to your PageNotFound.aspx.
Here's some more infomtion on configuring custom error messages in IIS 6.0.

ASP.NET Routing not firing when site is published to remote host

I have a website that was originally written in webforms to which I have added MVC functionality. When debugging locally it works fine, however, once published and uploaded to my host the routes do not work and return a 404.
I am pretty sure that I have uploaded all the correct files. Would just appear that routing is not working.
Any idea?!
(the site will still serve normal aspx pages fine)
I think the problem may be related to Mixing ASP.NET MVC into ASP.NET WebForms
But I cant see from that thread what the solution was. It looks like it might be something to do with the app_pool mode - but I am running in integrated mode, which is right AFAIK
UPDATE 2
So I think I have routing working. I basically created a new MVC app and went through theweb config file line by line and made sure I have everything I needed. Funnily, none of the tutorials online mention the correct additions you need to make. hey ho..
I have have another issue mind you...
When i load my mvc page I am greeted with the message:
The SessionStateTempDataProvider requires SessionState to be enabled.
I've added a line to web.config to enable sessions (wasn't aware they were off) and it still doesnt work.
UPDATE
I created a new asp.net MVC project and ended up going through web.config line by line and ensuring that everything that related to MVC was included in my hybrid app. Suffice to say that none of the guides mention all the settings that are required (i was using the book professional asp.net mvc 1.0). I then included the global.asax file which is not published and set up a route so that a request for / was not being caught by MVC. I also had to enable sessions in web.config.
And now it works!
Should I mark this question as the answer...not sure on the protocol here :)
I was going through the same thing because I deploy with compiled views. I don't know why but global.asax isn't included in the Release folder that I uploaded. I just figured it was compiled into one of the DLLs. I was getting 404 for everything so I tried uploading global.asax and the site came to life.

Resources