Skip to main content

How to use membership system in ASP.NET project?

If you want to add membership capabilities (register, log in, managing roles etc.), to your web page, follow the post below.

You must have noticed that there are “Log in” and “Register” links in the top right-hand corner in an ASP.NET web page. Even thought the pages are exist, you won’t be able to use them unless you’ve done the corresponding installation and configuration process.

I will be explaining how to install membership tables and configure it.

Steps

  1. Run aspnet_regsql.exe in .NET Framework folder

    Running aspnet_regsql.exe
    Running aspnet_regsql.exe
  2. A wizard which is going to help us to install necessary membership tables in the database will show up. Follow the steps through the wizard. In “Select a Setup Option” window, choose “Configure SQL Server for application services“.

    Choose first option to create membership tables
    Choose first option to create membership tables
  3. In “Select the Server and Database” window, make sure you’ve entered server name with instance name and selected the appropriate database from the combo list.

    Database settings
    Database settings
  4. After completing the wizard, one more setting will be left. Go to your “web.config” file in Visual Studio. Change the connection strings with the one you use for these tags: “membership“, “profile“, “roleManager

    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ltesitecheckConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ltesitecheckConnectionString" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ltesitecheckConnectionString" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
  5. You’re all set! In order to manage users, roles and rules, go to “Project > ASP.NET Configuration > Security” in Visual Studio.

    Web Site Administration Tool
    Web Site Administration Tool

Solved: “ASPxGridView component’s GetSelectedFieldValues method does not retrieving values”

One of the amazing components in DevExpress suite is ASPxGridView. It has a method called GetSelectedFieldValues for retrieving values which are selected by the user. However, you might run into a problem such as retrieving nothing!

Problem with getting selected values in the runtime?
Problem with getting selected values in the run time?

 

Here is the code that you use and fail retrieving data:

Default.aspx.cs:

List<object> fieldValues2 = gridSiteList.GetSelectedFieldValues(new string[] { "column1", "column2" });

Default.aspx:

<dx:ASPxGridView ID="gridSiteList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Width="297px">
     <Columns>
          <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="40px">
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="column1" VisibleIndex="1" Width="130px" Caption="Name">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="column2" VisibleIndex="2" Width="130px" Caption="IP">
          </dx:GridViewDataTextColumn>
     </Columns>
</dx:ASPxGridView>

Solution

ASPxGridView needs you to specify the name of a unique column to work correctly. In order to specify it, simply add this parameter into the component definition:

KeyFieldName="column1"

So, the edited ASPX code look like this:

<dx:ASPxGridView ID="gridSiteList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" KeyFieldName="column1" Width="297px">
     <Columns>
          <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="40px">
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="column1" VisibleIndex="1" Width="130px" Caption="Name">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="column2" VisibleIndex="2" Width="130px" Caption="IP">
          </dx:GridViewDataTextColumn>
     </Columns>
</dx:ASPxGridView>

You don’t need to change anything in CS file.

How to configure timeout value in ASP.NET project and stay away from “ThreadAbortException”

You may run into this error message in your ASP.NET project:

System.Threading.ThreadAbortException: Thread was being aborted.

It means that executing some part of your code took time more than it is allowed. You can trace the stack to see which lines they are. If you trust your code, it is a good idea to increase timeout value so the thread won’t aborted again.

Resolution

Add this code or change it if it’s already exist in your web.config file:

<system.web>
     <httpRuntime targetFramework="4.5" executionTimeout="360000" maxUrlLength="10000" maxQueryStringLength="80000" />
</system.web>