ASP.NET MVC Routing - asp.net-mvc-routing

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).

Related

IIS 10 giving 401.3 access denied for PUT, DELETE, or PATCH for specific path

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.

Elmah (mvc4) ignores the customErrors (but it logs)

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.

How to configure MVC config file for to have no caching

I am trying to figure out how to configure a ASP.NET MVC2 config file to have absolutely no caching. My current config file has this xml node...
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ZeroCacheProfile" duration="0" varyByParam="*" location="None" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
That would indicate to me, that no caching is going on with with this application. Am I missing something? Will continue to browse the internet searching for the most succinct answer. Thank you.
Defining a cache profile in web.config per se doesn't do anything useful other than defining a cache profile. There must be something using this cache profile otherwise it stays a simple definition. So that's half of the job.
The second half is to decorate all your controllers or actions that you would like to disable caching for with the [OutputCache] attribute:
[OutputCache(CacheProfile = "ZeroCacheProfile")]
or if you want to do this for all controllers of your site define a base controller that all your controllers derive from and then decorate this base controller with the aforementioned attribute.

Struts2 seo-friendly url?

Instead of
Users.action?login=foo
I want to have
/users/foo/
In spring mvc they have "URI templates" for it, but they are only annotation-based.
Is it possible to do such url-s in Struts with xml from-the-box?
The only one thing I found was external tool: http://www.progbear.com/voice/2010/struts-2-create-friendly-url-with-urlrewritefilter
wildcards in struts do not work with "/" and cannot pass parameters to action.
Sure I can get this info from request but I believe Struts should support it.
Yes, you can do this out-of-the-box with Struts2. Check out the NamedVariablePatternMatcher, which I described here.
In your case, you would need to enable the options in the answer that I linked to above and then map your action as:
<action name="users/{login}" class="...">
...
</action>
You could also look into the rest plug-in.

ASP.NET MVC users not being copied over on publish

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.