ASP. NET froms verification of small issues solved Process

Source: Internet
Author: User
Document directory
  • Configure the application to use forms authentication

1. On the logon page, login. aspx. CS writes the user information to context. User.

// Assign the current user object instance to context. user. This will load the complete user information to the authentication system provided by ASP. NET. Context. User = newuser;

2. Print the user information after verification.

  string aaa = Context.User.Identity.Name;

The result shows that the authentication is always fail. The tracking finds that the AAA here is the login user information of windows. What should I do?

That is to say, Forms authentication is changed to Windows authentication.

Refer to msdn

Froms Verification:

Using Forms authentication, you can use the created login form to authenticate the user name and password. Unauthenticated requests are redirected to the logon page on which creden。 and submission forms are provided. If the application verifies the request, the system issues a ticket containing the key used to recreate the identity of subsequent requests.

One easy way to use forms authentication is to use ASP. NET membership (which stores user creden。) and ASP. NET logon controls (which can be used to create logon pages ).

One convenient way to use forms authentication is to use ASP. NET membership and ASP. NET logon controls. ASP. NET membership provides a way to store and manage user information, and includes methods to authenticate users. ASP. NET logon controls use ASP. NET membership, and encapsulate the logic required to prompt users to enter creden。, verify users, restore or replace passwords. In fact, ASP. NET membership and ASP. NET login controls provide an abstraction layer on the form authentication, replacing most or even all of the work that is usually required to use forms authentication.

Configure the application to use forms authentication
  1. Open the Web. config file in the root directory of the application.

  2. If the application root folder does not contain the Web. config file, create a text file named Web. config and add the following elements to it:

    <?xml version="1.0"?><configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">    <system.web>    </system.web></configuration>

  3. InSystem. WebElement, createAuthenticationAndModeSet propertyForms, As shown in the following example:

  4. <system.web>  <authentication mode="Forms">  </authentication></system.web>


    InAuthenticationElement, createFormsAnd set the following attributes:

    • LoginurlSet to "Logon. aspx ". Logon. aspx is the URL used by ASP. NET to redirect requests without an authentication cookie containing the request content.

    • NameSet to. aspxformsauth ". This is the suffix set for the cookie name that contains the authentication ticket.

    <system.web>  <authentication mode="Forms">    <forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">    </forms>  </authentication></system.web>

  5. InSystem. WebElement, createAuthorizationElement.

    <system.web>  <authentication mode="Forms">    <forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">    </forms>  </authentication>  <authorization>  </authorization></system.web>

  6. InAuthorizationElement, createDenyAndUsersSet the property to "?". This indicates that the user who fails identity authentication will be rejected (by "?" To access resources in the application.

    <system.web>  <authentication mode="Forms">    <forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">    </forms>  </authentication>  <authorization>    <deny users="?" />  </authorization></system.web>

  7. Save and close the Web. config file.

 

Modify web. config as follows based on my actual situation:

      <authentication mode="Forms">        <forms name="forums" path="/" loginUrl="login.aspx" protection="All" timeout="40">        </forms>      </authentication>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.