Positive Change Creations

Linking people by building rich, interactive communities
Welcome to Positive Change Creations Sign in | Join | Help
in Search

.NET web controls

  • Fixing the problem where every aspx / html change forces you to recompile

    I have found that on some projects I have worked on, that every time I change any aspx or html code in a .net 2.0 website project, and click refresh on the browser, I get an error message telling me the .dll can not be found.

    Compilation Error

    An error occured during the compilation of a resource required to service this request.

    The dll name is one of the long named page specific dlls that the .net runtime uses to compile the code behind for this page.

    After much investigation I found that the error is due to .net monitoring the number of changes I make to the project and then wanting to recompile the project after a certain number has been reached. By default this number is 15. This is why some people on the forums say it seems to happen intermittently. It doesnt, it happens after 15 changes.

    However, sometimes this default number is overwritten and this is the case in Commerce Server web sites. It happens everytime you make a change.

    This is obviously extremely annoying to have to recompile every time a simple html change is made.

    The reason this doesnt happen in a live environment is because .net actually does recompile the changes on the next request. In a debug environment, the debugger if attached locks out .nets ability to recompile the project and so you get the above error.

    To fix this problem, you can add the attribute:

    numRecompilesBeforeAppRestart

    to the compilation node in the web.config file.

    I have set mine to 500 whilst debugging.

    I now can change the html / aspx without that error appearing.

  • Adding UserControls dynamically using c# into a website project

    As a web project does not have a namespace that we can use in our code, loading page or user control classes at first seems impossible.

    However, there is a method called LoadControl that allows us to load the class in using its filename. For this to work, you first have to use the

    <%@ reference

    in the aspx page that you want to create the page in. So if you are creating a user control, you would use this in the aspx page underneath the page declaration.

    <%@ reference control="myUserControl.ascx" %>

    Then you will need to compile you project so that visual studio recognises the tag.

    Next you can now create your control using

    MyControl thisControl = (MyControl)LoadControl("MyControl.ascx");

    You can now access all of the properties of your control class and add it to the page as you wish.

     

  • The Login Controls with Membership and Profiles

    Having just set up .net membership, profiles etc using the standard .net 2.0 login controls, I thought I would highlight some of the problems here that I came across when implementing a pretty standard solution.

    Issues with implementing the standard .net user controls with standard membership providers

     

    Web.Config configuration issues

     

    Make sure that the defaultProvider property of membership tag is set to be the same as the name attribute on the provider that you are intending to use.

     

    <membership defaultProvider="memProvider">

    <providers>

          <add applicationName="profileTest" connectionStringName="dbConnect" name="memProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Clear" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="3"/>

    </providers>

    </membership>

     

    Make sure that the applicationName is the same as the one that is defined in the SQLServer database table ‘aspnet_Applications’ on the database that you have created to hold the membership data in. (default database aspnetdb). Check the column ‘ApplicationName’

     

    <membership defaultProvider="memProvider">

    <providers>

          <add applicationName="profileTest" connectionStringName="dbConnect" name="memProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Clear" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="3"/>

    </providers>

    </membership

     

    To change the password strength

     

    To change the default password strength you must first override the machine.config value for the attributes ‘minRequiredNonalphanumericCharacters’ and ‘minRequiredPasswordLength’. Either change these in the machine.config or remove the key and then add the provider again to override in the web.config.

    <remove name="AspNetSqlMembershipProvider" />

    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />

     

    Source: http://hostlibrary.com/ChangingthePasswordComplexityinASP.NETV2.0.html

     

     

    Can’t Log in problem

    If the login control will not log in even though you have definitely entered the correct log in details and you have checked that the applicationName is correct (see above) then make sure that you have not over ridden the event handler for the login control.

    If you double click the control and have the event handler: Login1_Authenticate is not present.

    If it is, then either delete it as this will stop the provider from working, or implement your own authenticate code into the event handler user if(Membership.ValidateUser(username,password)) to check if the user is successful.

     

    Resources:

     

    Standard .net control controlAdaptor classes which contain control adaptors to make the login controls accessible. (to a degree).

    http://www.asp.net/CSSAdapters/Default.aspx

     

This Blog

Post Calendar

<August 2008>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Syndication