I've just migrated a MVC3 project to a 4.
I also installed the newest update of ELMAH.
I do have an issue with unhandled exceptions.
In my web.config I have this:
<customErrors mode="On" defaultRedirect="/Error/Error" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="/Error/NotFound" />
</customErrors>
When I get an unhandled exception, Elmah logs it, no problem there, but it doesnt send me to the Error/Error view. It also doesn't do the 'ResponseRedirect'
What it does instead is keep the URL as it was, and it shows me the Error.aspx view from the Shared folder.
How do I change the settings somewhere, that the customErrors won't be ignored?
If you are seeing the Error.aspx page then definitely HandleError filter is playing behind it. Go to Global.asax.cs and check HandleErrorAttribute is not added in the RegisterGlobalFilters method.
Also make sure you haven't overridden the OnException method of the controller and doing something manually yourself.
Related
I'm working on a REST API, and doing test and prototype work on Windows 10 with its native IIS install. The API is written in C#. I've created a class that derives from IHttpHandler, and derive from that to implement classes for my API's nouns. (This allows me to commonalize logging, config, auditing, etc, in my base noun class). To implement verbs, the derived classes override the base class' functions for GET, POST, etc.
Anyway, one of the nouns I have is for access to the application's log. The path for this is /log. In it I've implemented GET, to read the log, and DELETE, to clear the log. GET works fine, however, DELETE gives me a 401.3 from IIS. I also get the same 401.3 if I try PUT or PATCH. PUT and PATCH are not implemented in the Logging class, so they should return a not implemented message. I do get the not implemented message if I try POST (which is not implemented in exactly the same way that PUT and PATCH are not implemented).
As part of trying to narrow down this behavior, I checked whether there were specific verbs being blocked by request filtering (there weren't). I checked whether Process Monitor was catching file system access denials at the underlying path (it wasn't... things never got that far.) I then tried adding another handler mapping - exactly the same as the first, but with a different path name:
<handlers>
<add name="BLOBRepoLog" path="log" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
<add name="BLOBRepoLogSanityCheck" path="foo" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
</handlers>
Using Postman, if I call DELETE on /log, I get the 401.3. If I call DELETE on /foo, it works correctly. If I call PUT on /log I get the 401.3. If I call PUT on /foo, I get the correct not implemented message.
Anyone have an idea why IIS should be doing extra scrutiny on verbs called for the /log path?
Thanks,
Paul
I had a similar issue where Put and Delete weren't working, it turned out for me that Webdav was the issue. In my case I didn't really need it so I uninstalled it and everything worked.
When trying to update a service reference in a class library (VS2013), i get the following error.
"The configuration for the service reference could not be updated due to the following issue: An error occurred creating the configuration section handler for system.serviceModel/bindings: AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only."
This same error happens when i try to delete the reference as well.
Any help in sorting would be greatly appreciated.
I've had the same issue after updating to VS2013 Update 2.
I've solved the issue by temporarily cutting the whole system.serviceModel section out of web.config, pasting it somewhere else like Notepad. Then, I've saved the web.config without the service model section. Then, I was able to update the service reference successfully. After updating the service reference, I've pasted the service model section back to web.config and it worked successfully.
I was able to work around this similarly to Can by temporarily removing the extensions element of the system.serviceModel section and any associated extension elements. In my case the extensions were Azure Service Bus extensions.
In my experience it has been as simple as to delete the service reference and re-adding it. For example, last time it happened it was on a WebService (not WCF, the old one), and the error started appearing after we changed one of the classes that was being sent as a return from different routines/functions. After adding one more property to the class, it started going crazy and prompting errors everywhere.
Just a simple Delete and re-Add Service Reference did the trick.
Only need to one time remove <system.serviceModel> section from web.config. After Create first service refrence , this section rebuild by Vs.
I know this has already been asked. I am in a crisis here.
I cannot make a PUT method to work. Just REST services. iis 7 windows 7 64 bits.
I get Method not allowed, and not a single hint. I am using a .svc file.
Please help!
Thanks
There could be many reasons why this is happening, I would recommend that you add the below to your web.config (just before the is closed), so that you can get some diagnostics information on what your WCF webservice is doing :
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\webservicelog.svclog" />
</listeners>
</source>
</sources>
Also, are you placing PUT in the method operation contract like below :
[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "DoWork")]
I have been downvoted, but if you check around, many people has been troubled by this.
So, things I learned:
ENABLE Trace Failed Requests!!! I was relunctant, and I should have done it before. Might have saved a full day and night, because I am the kind of guy that get obsessive with technical problems.
PUT methods can not be tested via url in a browser!!!!
I finally solved it by uninstalling WebDAV, thanks to Failed Trace!! I had already tried that, but I was sometimes checking with Chrome Rest Extension, and sometimes via URL in a Browser. Apparently, when I firt tried WebDAV uninstall, I never checked with Chrome Rest...
I know, I know, a was until yerterday a complete newbie. Now I am just a newbie.
I ended up writing my own code to consume the services to have full control.
For you guys having the same problem, please enable tracing failed request. Then, in the XML output, look for:
405
Close to that you will found the bastard causing it. In my case, it was webDAV.
Rememeber to use a tool that actually sends a real PUT verb, like rest Chrome Extension, or your own app. NOT URL in a Web Browser.
Regards
I would like to ignore all urls in my site that start with /blog/...
I have /blog ignored with
routes.IgnoreRoute("blog/{*path}");
but this doesn't seem to be ignoring urls suchs as /blog/feed/rss
EDIT:
I left out that this is the very first item in RegisterRoutes method. No routes are being registered before it.
Alternatively you can use httpHandlers in your web.config to achieve this effect at a higher level.
<httpHandlers>
<add path="blog/*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
But besides that, your route should work. I don't see any reason it would not unless it was pre-empted by another route (this could happen if you are using AreaRegistration).
I'm new to ASP.NET MVC, and I'm trying to convert a very simple ASP.NET application to MVC with authorization.
I have it working locally just fine, but when I publish to IIS, the users database is apparently not copied over correctly (even though it is running on the same machine that I am developing it on)
It does not appear to be a database access issue, since when I create a new user using the Register link I can log in just fine. The problem is, all the users (and their associated roles) I created using the ASP.NET Web Site Administration Tool aren't being recognized. The error message it gives me is a simple "log in or password is incorrect" - there's nothing about not being able to access the database or anything like that.
Does anyone know where I should look for the source of this problem, or has anyone else had this problem before?
Potentially releveant additional information:
When I first published the project, I got an error in my web.config that said "ApplicationServices" was already defined, preventing me from accessing any page on the site. I "fixed" this in a manner that would be called "hacky" only if someone was trying to be polite - I added "<remove name="ApplicationServices" />" right above it, so that portion of the web.config looks like this:
<remove name="ApplicationServices" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Any ideas?
Roles and Users are partitioned by ApplicationName. Check the aspnet_Applications table and compare that to what you see in aspnet_Roles and aspnet_Users.
This post by Scott Guthrie explains what is probably happening, and how to configure the ApplicationName on your providers.