1
Vote

Custom routes Asp.Net Identity 2.0.1 Unauthorized redirect to login not working

description

Forms Authentication used to redirect to the login page when a folder was configured to restrict authentication to a user. As configured in the web.config, in the folder.
<system.web>
    <authorization>
      <deny users="?"/>      
    </authorization>
</system.web>
Which would redirect you to the login page with the returnurl of where you wanted to go in the first place. The authorization works ( Identity 2.0 Beta1 prerelease ) but there is no redirect to the login page when using Custom Routes
Now, after implementing identity which does everything else quiet well, when I try to access a page that requires me to be logged in I see a YSOD saying.
An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.
I've used the default template from vs2013 and it works with FriendlyUrls or the actual path, just not with the custom route. (which worked with Forms Auth)
routes.MapPageRoute( routeName:"login", routeUrl: "login", physicalFile: "~/Account/Login.aspx" );
For example I have a page located at /Account/nightlife/stream.aspx which has the above web.config in the folder Account

So when I use the full path it works and redirects me to the login page with

http://mylocaliis/login?ReturnUrl=%2FAccount%2Fnightlife%2Fstream.aspx (without the .aspx in the case of friendly urls)
But with Identity and the custom route enabled the redirect dosent happen and I see the YSOD
So for example if i tried to access the resource (when I am not logged in) with its custom route url

localhost/stream (defined by the custom route - routes.MapPageRoute( "nightlife_stream", "stream", "~/Account/nightlife/stream.aspx" ); )
I see the YSOD.

comments