Failed to forward my controller login result

I am new to C # and the asp.net world. So the question I'm going to ask can be rather lame, I hope that you will carry everything with me :). Ok, so I read the book and understood how authentication and authorization in asp.net happens.

Now I have defined my authentication and authorization as follows in my web.config;

<authentication mode="Forms"> <forms loginUrl="~/Home/LogOn" protection="All" path="/" timeout="30" name="MyCookies" /> </authentication> <authorization> <deny users="?"/> <allow users="*"/> </authorization> 

and then I started to create my registration form. Which looks like this:

 <form method="post" action="../Home/LogUser"> <fieldset> <legend>Log On</legend> <p>User Name</p> <p><input type="text" name="txtUserName" id="txtUserName" size="30"/></p> <p>Password</p> <p><input type="password" name="txtPassword" id="txtPassword" size="30"/></p> <p><input type="submit" name="btnSubmit" value="Log On"/></p> </fieldset> </form> 

My problem is that since I decided to reject anonymous users in my web.config, when I try to submit my form, which directs the controller, it returns to the login page. How can I handle this situation? perhaps I understood the whole journal paradigm in asp.net, in which case I humbly appreciate the explanation in this regard.

+4
source share
1 answer

Welcome to asp.net. I especially like the MVC framework. I hope you do it.

Many points offering

1) if you use the MVC framework, this approach is NOT recommended. A higher approach is to use the [Authorize] attributes for controllers and / or methods that you want to close to unauthenticated users.

This approach allows you more flexibility to decide where your users can anonymously, where they can authenticate, and where only certain roles can be performed [Authorize(Roles="Admin")]

2) If you want to continue with web.config settings and authentication locations so that users can access certain places, add this code to web.config

 <location path="~/Home/"> <system.web> <authorization> <allow users="?" /> </authorization> </system.web> </location> 

3) What I do not understand from your question was your intention. If you want the user to be able to log in, you should open ~/Account/Logon , and your login form should (preferably) be sent there.

+3
source

All Articles