ASP.NET MVC action and virtual directory with same path

Is any special routing or IIS config needed when a controller action uses the same URL as a virtual directory?

I have an ASP.NET MVC 1.0 application that needs Windows Authentication applied to a single action ("/Login/FromWindows"). To do this, we've setup a virtual directory with the same path as the action (e.g. "/Login/FromWindows") and enabled Windows Authentication on it in IIS.

When I visit the /Login/FromWindows URL, I get an empty HTTP 200 response and nothing is logged in the server text log. The "FromWindows" action should be logging messages and redirect the user to the home page.

It seems like the action code is simply not being executed, so there is possibly a conflict with the virtual directory.

Route config in Global.asax.cs

public static void RegisterRoutes(RouteCollection routes)
{
    // snipped: ignored routes for images, scripts, etc.

    routes.MapRoute( "Default", "{controller}/{action}",
        new { controller = "Home", action = "Index" } );
}

Answers


You are right, the action code isn't being executed. That's because existing file paths (virtual or not) take precedence over MVC routing rules.

Why are you using a virtual directory? Just set authentication to windows in the web.config and use the [authorize] attribute over the corresponding action methods.

Web.config:

<configuration>
     <system.web>
          <authentication mode=”Windows” />
     </system.web>
</configuration>

Action Method:

[Authorize]
public ActionResult SomeAction()
{
     return View();
}

Visit http://www.asp.net/mvc/tutorials/authenticating-users-with-windows-authentication-vb for more information on mvc with windows authentication.


Need Your Help

Storing pointers in Core Data

iphone ios core-data uilocalnotification

I am storing some objects in core data that have inherent life spans. I was scheduling local notifications on object creation for this lifespan and then handling the object went the notification fi...

vba programatically have excel forget window structure

excel vba excel-vba

In Excel 2013, Excel likes to remember Excel windows (not worksheets) that were open, and when the workbook is opened again, also open up those windows:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.