Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Routing is one of the core concept of any <code>ASP.NET MVC</code> application. A <code>URL</code> of a <code>MVC</code> application is the combination of your <code>Application root URL</code> followed by <code>Controller</code> name and then <code>Action</code> to which request has been made e.g. </p> <pre><code>http://localhost:55875/{controller}/{action}/{optional parameters} </code></pre> <p>You probably have chosen new project with <code>Account Controller</code> and <code>Authorization</code> membership providers. As fellow members has mentioned, the <code>Authorize</code> attribute is probably the main reason you are being redirected to <code>logon</code> page. </p> <p>From the documentation of <a href="https://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute(v=vs.98).aspx#using_authorizeattribute" rel="nofollow"><strong>Authorize attribute</strong></a>:</p> <blockquote> <p>If an unauthorized user tries to access a method that is marked with the Authorize attribute, the MVC framework returns a 401 HTTP status code. If the site is configured to use ASP.NET forms authentication, the 401 status code causes the browser to redirect the user to the login page.</p> </blockquote> <p>In browsers, whenever you hit enter key in address bar, browser always make a <code>GET</code> request to the server for resources.</p> <p>That is what could have happened. Either your <code>Admin Controller</code> or its <code>Index()</code> method is decorated with <code>[Authorize]</code> action filter attribute e.g.</p> <pre><code>public class AdminController : Controller { ///&lt;summary&gt; /// This view will open whenever you make a HTTP GET request to your Admin /// controller without providing any action method name in request explicitly. /// Because it is decorated with Authorize attribute, any user who has not logged in /// will be redirected to the login page... ///&lt;/summary&gt; [Authorize] public ActionResult Index() { return View(); } } </code></pre> <p>You may wonder <strong>why did application redirected to login view?</strong></p> <p>This is because by default this action has been set in your application inside your <code>web.config</code> file.</p> <pre><code>&lt;authentication mode="Forms"&gt; &lt;forms loginUrl="~/Account/Logon"/&gt; &lt;/authentication&gt; </code></pre> <p>MVC leverages the power of built-in authentication logic and redirects the user to view that has been set under <code>loginUrl</code>.</p> <p>Try removing the <code>[Authorize]</code> action filter just <strong>for a change</strong> and see what happens. In the end it is your business logic to decide on which views you need to have only authorize or anonymous access.</p> <p>However, you may also take a look at <a href="http://blogs.msdn.com/b/rickandy/archive/2012/03/23/securing-your-asp-net-mvc-4-app-and-the-new-allowanonymous-attribute.aspx" rel="nofollow">AllowAnonymous attribute</a>. It allows you to skip authorization for a perticular <code>contoller</code> or <code>action</code>.</p> <pre><code>[Authorize] public class AdminController : Controller { ///&lt;summary&gt; /// Skips Authorization.. ///&lt;/summary&gt; [AllowAnonymous] public ActionResult Index() { return View(); } ///&lt;summary&gt; /// Only allows authorize access... ///&lt;/summary&gt; public ActionResult Secure() { return View(); } } </code></pre> <p>You can customize/override the behavior of these action filters as well.</p> <p>Notice, <code>[Authorize]</code> has been added to <code>controller</code> itself if you have selected the project with internet and membership providers which will make all the actions inside this authorized except those with <code>[AllowAnonymous]</code> filter (if exists).</p> <p><a href="http://msdn.microsoft.com/en-us/library/dd410209(v=vs.100).aspx" rel="nofollow"><strong>This article has good overview of Action filters in MVC</strong></a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload