Get UrlRewritingNet to work with IIS 7.0

There is a well known problem using url rewriting functionality with UrlRewritingNet and IIS 7. The problem can be solved by setting the pipeline mode of the application pool to be in classic mode. Looking forward for the next version :).
Actually the url rewriting functionality can be achieved much easier with IIS 7.

AJAX: Timeout problem by asyncronous postback

The most common cause of this problem is the time of asyncronous response. It occur when the response takes more than 90 seconds. First of all be sure that there is no client script in the update panel. Use

ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "tmp", "<script type='text/javascript'></script>", False)

to register such scripts during loading page.

If the reason is long calculations on the srever you can change the asyncronous timeout in the ScriptManager tag.

<asp:ScriptManager ID="ScriptManager1" AsyncPostBackTimeOut="3600" runat="server" />

This makes the response to be valid an hour.

How to sum values in Excel only from visible cells

There is a good article in microsoft support site for this problem and the example works fine.

How to use a VBA Macro to Sum Only Visible Cells

see also how to create user defined functions (UDF)
in Excel

Creating User Defined Function in Excel (UDF)

You have to use VBA for making User Defined Function in Excel (UDF).
Click on Developers tab in the ribbon (Excel 2007) then click on Visual Basic or use Alt+F11.
Then insert a new module by Insert->Module and write your function there.
The functions will be inlcuded Insert Function dialog box in "User Defined" category.

To use the functions in another excel documents you must save them in your own add-in by saving the file as add-in file .xla or .xlam for Excel 2007. Then load the add-in by Start->Excel Options->Add-ins->Go.

How to enable VBA on Excel 2007 (Microsoft Office 2007)

The developer's functions of excel and VBA are disabled by default. They can be unlocked using Start->Excel Options window. Check "Show developers tab in the Ribbon" in Popular section. After clicking OK the developers tab is shown at the last place in the ribbon.
Another important thing is the saving xls documetns with recorded macros or inlcuded VBA scripts. You must save the file by Save As dialog box as an Excel Macro-Enabled Workbook with extension .xlsm .

Error rendering a custom control

Maybe this is a little MS Visual Studio bug. It is connected to the control registering in the page in case of using a control defined in App_Code folder, not in another assembly. The exception thrown while opening design view of the page is:

Error Rendering Control - [control] An unhandled exception has occurred. There was an error parsing the theme. The assembly attribute cannot be an empty string.

So the VS environment doesn't recognize the control defined in the App_Code. Therefore the control regitration must inlcude the assembly name - "App_Code"

<%@ Register TagPrefix="my" Namespace="MyControls" assembly="App_Code" %>

or

<add tagPrefix="my" namespace="MyControls" assembly="App_Code" />
in web.config - pages/controls section

SQL Server Express permissions

Fix for exceptions like these:
"CREATE DATABASE permission denied in database 'master'",
"EXECUTE permission denied on object "
"SELECT permission denied on object"

Asp.NET uses the NETWORK SERVICE account (for Windows Server 2003) and ASPNET user for Windows XP. If we use windows authetincation for using sql express we need to add these users as sql server logins:
SQL Server manager -> Security -> Logins -> add "NT AUTHORITY\NETWORK SERVICE" or ASPNET
Then click on the properties menu of the login and make the login dbcreator. This will fix the first of the exceptions above. Then with User Mapping setting we can add permissions explicitly to the desired database -> dbowner gives all needed permission.

How to get Profile instance out of asp.net page,

The way of getting Profile instance from a page context is Profile.GetProfile(). But how to do this when you need to get it from App_Code for instance. Here is the way:

MembershipUser mUser = Membership.GetUser(UserId);
ProfileCommon prof = (ProfileCommon)System.Web.Profile.ProfileBase.Create(mUser.UserName);

the object "prof" has all profile fields as in a page.

How to set page/script timeout on an asp.net page

The solution is pretty simple. Use Server.ScriptTimeout to set the timeout for the script in a page. The value is measured in seconds.

Server.ScriptTimeout = 3600

Use this in Page_Load event. The example makes the timeout to be an hour.

NOTE: using compilation debug="true" will ignore script timeout and it won't work. Make sure the debug value is false on the release version of web.config

FormsAuthentication.Authenticate vs Membership.ValidateUser

FormsAuthentication.Authenticate can be used with clear passwods to check user authentication:
if(FormsAuthentication.Authenticate(Username.Text, Password.Text))
{
FormsAuthentication.RedirectFromLoginPage(Username.Text, false);
}

This doesn't work if the password format is not clear. Asp.NET membership provider offers you Clear, MD5 or SHA1 represented passwords.
In case of using MD5 or SHA1 (specified in web.config, SHA1 is default for hashed passwords) the checking for user credentials should be done by Membership.ValidateUser which delivers the provider model for user authentication.

if( Membership.ValidateUser(curentUserName, pwd)){
FormsAuthentication.RedirectFromLoginPage(Username.Text, chkPersistent.Cheked);
}

The other things of authentication process can be left to the Asp.Net provider.

See also for web.config: authentication and authorization, machine key generation, password format, password salt ...

How to use SQL Express database for more than one application

Somethimes we need to use one database for more than one application, web, desktop or service.
The only thing to do is to get rid of the generation of a new user instance by the connection string in web.config. Assure that User Instance=False in the connection string and try again.

Javascript: How to cancel leaving page without saving

Preparing the javascript:
string jscript = "var needToSave= false;" +
"window.onbeforeunload = confirmExit;" +
"function confirmExit(){" +
"if (needToSave){" +
"return 'Are you sure you want to leave the page without saving?';" +
"}" +
"}";

Registering the script - safe for ajax:

ScriptManager smgr = ScriptManager.GetCurrent(Page);
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "", false);

On every field that changes the data and requires saving put:
control.Attributes.Add("onkeydown","javascript: needToSave=true;")

on the button that make save postback add:
control.Attributes.Add("onclick","javascript: needToSave=false;")

Page Cannot Be Found Issue on IIS 6 on Windows 2003

Also:
HTTP 404 - File not found

First of all be sure that the default document list contains the page you are requesting (IIS -> Server Node -> Site node -> right mose click -> Properties -> Documents
Also set the necessary permission to the web folder (NETWORK SERVICE must have read/write rights)
Check if the asp.net status is allowed (IIS -> Server Node -> Web Service Extensions -> Asp.net must be allowed). This can be done during the installation of IIS.

ASP.NET Export content to Excel files.

The most common problem during exporting page content to an excel file is the following exception: RegisterForEventValidation can only be called during Render();
The only thing you need to do is to set enableEventValidation ="false" in web.config (affects all your pages) or in the head page line.

If you want to render a control into an excel file (using HTML representation) the VerifyRenderingInServerForm() method must be overridden.

public override void VerifyRenderingInServerForm(Control control){}

This confirms that an HtmlForm control is already rendered.

... and the example - rendering existing gridview control into a xls file:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=file.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); ;
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
htmlWrite.Write("text text");
htmlWrite.WriteBreak();
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

How to recover Mozilla Firefox Bookmarks

Very strange problem. Sometimes firefox' bookmarks dissapear. May be this is connected with NTFS problems (sometimes solved by chkdsk c: /f). But the best way to recover the bookmarks is to get them again from the last firefox archive. They are in

C:\Documents and Settings\[username]\Application Data\Mozilla\Firefox\Profiles\pypbblhs.default\bookmarkbackups

and the last archive must be ranamed and put into

C:\Documents and Settings\[username]\Application Data\Mozilla\Firefox\Profiles\pypbblhs.default

This solved my problem :)