DotNetNuke DNN

...now browsing by category

 

Fix for ASP.Net webform postback error, “..Operation is not valid due to the current state of the object”

Wednesday, November 13th, 2013

Got this error sometimes ago and, today in another application, it appeared again. This occurred when I had a relatively large number of rows of data to be posted back in a web form, said, 178 rows, in this case. Before the Postback event handler even got hit, the IIS already complained and threw this at me:

DotNetNuke.Services.Exceptions.PageLoadException: Operation is not valid due to the current state of the object. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object. at System.Web.HttpRequest.FillInFormCollection() at System.Web.HttpRequest.get_Form() at System.Web.HttpRequest.get_HasForm() at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) at System.Web.UI.Page.DeterminePostBackMode() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --

There was no much explicit information to derive more useful details from; but it is obvious that this must have something do with the number of data post back to server since in an earlier upload, with rows less than 30, the same Postback event did not have any problem. I remembered last year I had done some research on this issue after I got this error first time while posting back a large data grid, so I dug out that application’s web.config file, and copied one line from that file and pasted it to the AppSettings in the web.config under the DotNetNuke portal root (where my app was running as a Module), and that fixed the Postback error. This time, I want to share this out loud and also it will help myself in search for solution if I will encounter the same issue again later.

So all I had to do was to add this line anywhere in the appSettings section in a web.config that is in the root of the website:

 <add key=”aspnet:MaxHttpCollectionKeys” value=”1000″/>

The number here is the maximum number of rows of a server data-bind control such as a GridView or a Repeater control. In general, however, it is not a very good practice to have a large number of rows post back over wire and that’s probably why IIS has this implicit cap on this at first place.

Manually added Elmah to a deployed Asp.Net website

Tuesday, June 18th, 2013

Sometimes I found that it was frustrating to not know what exception detail was when an exception was thrown from a production website. At that point, the all-mighty Elmah error logging and exception handling plug-in came to my mind. But all my previous Elmah plug-in was added during web project development and deployed along with the project to hosting server. How to go about plugging in an Elmah when my website is already up there and running? Here were the steps I went through the other day to accomplish exactly that:

  1. Downloaded the elmah sql script file from https://code.google.com/p/elmah/downloads/detail?name=ELMAH-1.2-db-SQLServer.sql&can=2&q= and executed it against the sql database ProdDB on the host. It went through and created the Elmah_Error table and related stored procs inside ProdDB database
  2. Now let’s manually add elmah.dll and configure the web.config to register elmah.
  3. Copied elmah.dll from one of my old projects that had Elmah already working to the target bin folder.
  4. Added to <configuration><configSections> the following:
    <sectionGroup name="elmah"><section name="security" type="Elmah.SecuritySectionHandler, Elmah" />
    <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /></sectionGroup>
  5. Added to <httpHandlers>:
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
  6. Added to <httpModules>:
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
  7. Added <elmah> to <configuration> right after </system.web> and before <system.net>
    <elmah>
    <!--<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Errors" />-->
    <errorLog applicationName="AppName" connectionStringName="connToProdDb" type="Elmah.SqlErrorLog, Elmah" />
    <errorMail subject="Website error via Elmah" to="stevey@yangsoft.com" from="webmaster@yangsoft.com" aysnc="true" />
    
    <security allowRemoteAccess="no" />
    
    </elmah>
  8. Last, but not least, in order to get the alert email sent out automatically to me, I needed to add the SMTP parameters to the mailSettings section in the <system.net>
    <mailSettings>
    <smtp deliveryMethod="Network">
    <network host="mail.domainname.com" userName="webmaster@domainname.com" password="password" port="numberthatworks" />
    
    </smtp>
    
    </mailSettings>

    (there was no <system.net>, so just created one)

  9. Added the following right after </system.net> and before <system.webserver>
    <!--deny annonymous access to error log-->
    <location path="elmah.axd">
    <system.web>
    
    <authorization>
    <allow users="*"/>
    <!--<deny users="?" />-->
    </authorization>
    </system.web>
    
    </location>
  10. Added to <system.webserver><modules>:
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
  11. Added to <system.webserver><handlers>
    <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
  12. Finally, it is completed! Now browsed to the site and manually generated some errors; immediately, I got an email alert; then I browsed to the elmah.axd, and it also rendered all the errors in a tabulated format nice and neat. Of course, more detail info is obtained by clicking on the detail link and you will be surprised how much exception stack trace has been caught.

Error while running PM>install-package MSBuildTasks

Thursday, March 14th, 2013

Got this error today while trying to install MSBuildTasks for a DNN Module development project and used NuGet:
install-Package : Method invocation failed because [NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper]
doesn’t contain a method named ‘AddFromFile’.”

I copied this error message to Google and found no match. After some digging, with portion of error words, found some tips linking to the fact that NuGet might need a face-lift. So I went back to VS2010 project, uninstalled the NuGet and re-installed it. Then run PM>install-package MSBuildTasks again, it went through with not error.

Hopefully this tip will be picked up next time someone would run into the same error message I got here.

Cheers!

DotNetNuke Portal Setup

Tuesday, March 12th, 2013

Steps to get DNN installed on VM and run:

  1. Downloaded DNN Install version from here http://dotnetnuke.codeplex.com/releases/view/81081. Did New Install, not “Install and Source Codes” for now.
  2. Created database DNN on VM Local machine SqlExpress and gave it full access to “Network Service” and my Windows Account
  3. Opened web.config from c:\Development\Dotnetnuke folder (where the dnn installation zip files were extracted to)
    and changed the connectionstring from:<add name=”SiteSqlServer” connectionString=”Server=(local);Database=DotNetNuke;uid=;pwd=;” providerName=”System.Data.SqlClient” />

    to:

    <add name=”SiteSqlServer” connectionString=”Data Source=LocalMachineName\SQLEXPRESS;Initial Catalog=DNN;Integrated Security=True”
    providerName=”System.Data.SqlClient” />

  4. Then went to IIS7/Default websites and added a new virtual directory, DNN and pointed to physical folder at c:\Development\DotNetNuke; Right clicked on the DNN VD and converted it to Application.
  5. Once converted to Application, I could set it to use the application pool that is specific to this app.
  6. So, went back to Application Pools and created one, “DNN” and changed Framework version to 4.0 and leave the Managed Pipeline Mode to
    default, “Integrated” and under the Process Model set the Identity to use Network Service instead of the default “ApplicationPoolIdentity”. The
    reason was that I could assign full folder access permission to the “Network Service” user account, but “ApplicationPoolIdentity” is not a
    actual Windows account.
  7. Set the Application pool to this newly created “DNN” ap.
  8. Browsed the site from IIS and just followed the onscreen instruction to go through the installation process. The database tables and objects
    are all created during this process. No need to run any sql installation script from Sql server side.