Thursday, 31 March 2011

Force file download instead showing in browser

Sometimes we would like to start attachment downloading instead showing in browser, for example for images (like PNG, JPG, GIF, etc). But usually browser displays content instead to prompt for saving. To fix this issue we just need to add one line of the code:

Response.AddHeader("Content-disposition", "attachment; filename=\"photo.png\"");

It adds header to the response and browser will prompt client for file saving.

Hope this helps.

Tuesday, 29 March 2011

Self-Signed Certificate and Trusted Root

Sometimes we generate own SSL certificates, for example internal use: development or testing. It saves us time and money. But usually browsers or other applications does not accept Self-Signed certificates.

This problem can be fixed easy. All what we need is to add certificate to the Trusted Root Certication Authorities. Sure, you should have admin permissions to do these steps:

1) Open mmc console.
2) Add Snap-in for Certificates.
3) Open Trusted Root Certication Authorities/Certiciates in Certificates.
4) Right click and select Import, then select your .cer or .crt file and click Next.
5) Select to put it under Trusted Root Certification Authorities, click Next and Finish.

Sometimes it requires reboot, but probably does not.

Hope this helps!

Sometimes DotNetNuke DataBase Grows Very Fast

This is very popular problem of DotNetNuke. DB grows very fast, ever you do not add any new modules and content is the same. The most popular problem is quick growing of the log tables SiteLog and EventLog.

One of my clients had this problem, because have been attacked by hackers and log grows very fast with errors. Another is because installed bad written module and this module throws a lot of exceptions.

You can check how many  records in each table with query like this:


SELECT COUNT(*) FROM {databaseOwner}{objectQualifier}SiteLog;

and

SELECT COUNT(*) FROM {databaseOwner}{objectQualifier}EventLog;

You can compare number of records for small period of time (for example 1 hour). If it grows fast, then here is a query to fix problem:

TRUNCATE TABLE {databaseOwner}{objectQualifier}SiteLog;
TRUNCATE TABLE {databaseOwner}{objectQualifier}EventLog;

This query removes all records from these tables. It can be runned from Host/SQL menu.

Hope this helps!

Sunday, 27 March 2011

How to upgrade DotNetNuke module or SQL scripts for new versions

DotNetNuke (DNN) is very good CMS. It allows easy and fast build new modules without any problems. Furthermore it allows to do an upgrade of old modules with beautiful and perfect process. For example, we have Module with version 01.00.00. During installation all SQL scripts locate in the 01.00.00.SqlDataProvider. This file contains all required SQL for correct Module functionality.

In case you need to upgrade your module, then all what you do is add to your module new file, like 01.00.01.SqlDataProvider. During installation DNN framework checks current version and runs all scripts above current version. It allows to do cumulative upgrade without any problems.

But some clients do an upgrade manually and it can be a lot of headache. So here is a way how to protect your SQL script:

IF(
NOT EXISTS(
SELECT sc.name 
FROM syscolumns sc
WHERE (sc.id IN 
(SELECT so.id
FROM sysobjects so
WHERE so.name='{objectQualifier}Survey'))
AND
(sc.name='CategoryID')
)
)
BEGIN
ALTER TABLE {databaseOwner}{objectQualifier}Survey ADD CategoryID int NOT NULL DEFAULT(0)
END

As you see, this script checks for field before creation. So, do not need to worry customer runs it twice or more times.

PS: My old teacher said: Good code allows to remove half of lines and continues to work :)

Saturday, 26 March 2011

Recursive references in the projects

This is the most stupid thing i have ever seen in development. Few years ago there was a project from the client. Project was live already and required some major changes for it. Customer sent me a source and once i started to work, i found about 5 recursive references like: project1 references to the project2 and project2 references to the project1. This is very big problem with development, it means something wrong with architecture. I have moved required methods to the separate project and it fixed 4 recursive references. But 1 recursive reference still exists. This issue did not allow to compile project. Fix was easy: need to set in the properties of the reference "Copy Local" = false.

Hope this helps!

Friday, 25 March 2011

No processes to attach in Visual Studio

Usually to debug projects for DotNetNuke i attach to the aspnet_wp.exe process. Its very good way on how to debug modules for DotNetNuke. But sometimes there was big confuse. Once i opened list of processes to connect i got it empty. It confused me, how it can be?

After deep debugging problem has been found.Source of problem is frozen processes IEXPLORE. Once i killed them in Task Manager and restarted IIS, everything goes back and i can attach to process for Debugging.

Hope this helps!

How to Delete Multiple Pages at One Time at DotNetNuke

Sometimes we have to remove several tabs/pages from the portal in DotNetNuke. With standard tools it can take some time, but with Pages Admin - Tabs Manager it can be done in few seconds and just 3 steps. Just look at these screenshots:

Thursday, 24 March 2011

How to send POST in background

Sometimes it needs to send POST in the background and get some info. In our case we had to send POST to the Protx (UK payment gateway - now its SagePay). Here is quick C# script how to do this:


private string ChargeProtx(CreditCardInfo objCardInfo)
{
    System.Net.HttpWebRequest request = 
(System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create("https://ukvpstest.protx.com/VSPSimulator/VSPDirectGateway.asp");


    request.Method = "POST";
    
string postData = "VPSProtocol=2.22&" +
"TxType=PAYMENT&" +
"Vendor=vendorname&" +
"VendorTxCode=" + objCardInfo.OrderID + "&" +
"Amount=" + objCardInfo.Amount.ToString().Replace(",",".")+"&"+
"Currency=GBP&" +
"Description=Direct_payment&" +
"CardHolder=" + objCardInfo.FirstName + " " + objCardInfo.LastName + "&" +
"CardNumber=" + objCardInfo.Number + "&";


    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
    request.ContentLength = byteArray.Length;
    System.IO.Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();


    System.Net.HttpWebResponse responseX = (System.Net.HttpWebResponse) request.GetResponse();
    dataStream = responseX.GetResponseStream();
    System.IO.StreamReader reader = new System.IO.StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();


    reader.Close();
    dataStream.Close();
    responseX.Close();


return responseFromServer;
}

Hope this helps!

Wednesday, 23 March 2011

How to insert one DNN module into another

This is not common task between different modules. But it is good to use controls inside of single project and this is very popular. So, to add one module to another you just need to know name of the primary control. Then your form will be like this:
<%@ Register TagPrefix="dnn" TagName="MultiEdit" Src="~/DesktopModules/dnn.MultiEdit/MultiEdit.ascx" %>
<dnn:multiedit id="objMultiEdit" runat="server"></dnn:multiedit>

Hope this helps!

How to rotate SQL Table

There was very good customer from Australia. He always had interesting projects. One of this project was to show report on products sales. At start it looks like simple project, but there were two issues:
1) Customer had very big amounts of data in MS SQL.
2) He would like to show data grouped in columns, not rows.

First version of project does grouping in the columns at the C# code, but with such big amount of data it was crazy slow and takes a lot of memory. This is why grouping has been moved to the MS SQL side. Here is a beautiful script (sorry, but can't remember original source):

Strip non word or sanitizing text in DotNetNuke

Sometimes in DotNetNuke we would like to prepare some text to the sanitized form. This is very common task for preparing FriendlyUrls. I would like to recommend to use core DNN method:

public static string StripNonWord(string HTML, bool RetainSpace)
Member of DotNetNuke.Common.Utilities.HtmlUtils

It allows to remove not only spaces, but also all non-URL characters.

BTW: This function used in Core DNN on Tabs updating.

Hope this helps!

Tuesday, 22 March 2011

Blocked references in Visual Studio

Sometimes, when you try to compile project for DotNetNuke in Visual Studio it can not to do this. Error says: can't rebuild, because .dll of the project is locked. Sometimes it was real headache for me, because was really unexpected and unusual. First time i thought its problem with IIS, but later i found its problem with Visual Studio references. So, there are 4 steps to fix this issue:

1) Remove all references from your project (or whole solution). Try to rebuild - it shows errors, because can't find references.
2) Close Visual Studio.
3) Open solution and add all references.
4) Rebuild solution. It works now.

Hope this helps.

Let me introduce myself

My name is Sergey. I am developer from the prehistoric times. It starts a lot of years ago, when computers were big and slow and continues until today. For this long period i have got great experience: machine codes, Assembler, Basic, Fortran, C, Pascal, Prolog, later Delphi, VB, C++, C#, Java, PHP, Perl and sure databases DBase, Paradox, FoxPro, MSSQL, MySQL, PostGre...Really it should take a lot of time to describe everything.

Since 2002 i develop for Web. More then 75% of my projects are DotNetNuke oriented. DotNetNuke (DNN) is great Content Management System and this is good to work with this product and community. But DNN is not my single priority. Also a lot of requests from customers on synchronizing data between different products. There were some projects for NopCommerce, Magento, OpenErp, OpenBravo Pos.

This work is good. It allows me to work remotely with different customers from around the world. Thats great opportunity and very good experience!