Archive for the ‘ASP.NET 2.0’ Category

How to remove HTML Tags From a String in c#

Thursday, 22 May, 2008 Leave a comment

A lot of websites allow users to input text and submit it to the site.
This could be forums, blogs, content management systems etc.
Imaging if the user writes HTML into these form fields?
It could be perfectly harmless when used for styling, but it could also be used the wrong way.
A typical scenario would be when a user enters JavaScript that does harmful things or embedding a style sheet that ruins the websites layout.
This is normally referred to as Cross-Site Scripting (XSS).
We have to mitigate that risk, and that’s when regular expression comes to the rescue.
Here is a very simple method that strips all HTML tags from a string or just the harmful tags – you decide.

Read more…

Categories: ASP.NET 2.0 Tags: ,

Global Variable 2nd method

Thursday, 15 May, 2008 3 comments

using System;
using System.Data;
public class UserInfo
private static string pin;
public static string Pin
get { return pin; }
set { pin = value; }
private static string fio;
public static string Fio
get { return fio; }
set { fio = value; }
public class QData
public class GData
public static void SetUserInfoPIN(string pin)
UserInfo.Pin = pin;
public static string GetUserInfoPIN()
return UserInfo.Pin;

Read more…

Tips for Nested Master Pages and VS 2005 Design-Time

Tuesday, 13 May, 2008 4 comments

There is a cool tip/trick, though, that will allow you to load a design-surface for a page that uses nested master-pages. This will allow you to use all of the control-designers and smart-tasks in design-view for the page (for example: to perform data-binding, auto-format things, and use any of the control wizards), and not have to change any-code to test it at runtime.

The tip/trick works by adding a base-page class to your project or solution that defines a new property called “RuntimeMasterPageFile” of type string. The base-class then overrides the page’s “OnPreInit” method and uses this property to set the Page object’s MasterPageFile at runtime:

Read more…

Large file uploads in ASP.NET

Monday, 28 April, 2008 4 comments

Large file uploads in ASP.NET

Uploading files via the FileUpload control gets tricky with big files. The default maximum filesize is 4MB – this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they’ll get an error message: “Maximum request length exceeded.”

Read more…

Categories: ASP.NET 2.0 Tags: , ,

Difference between Page.IsPostBack and Not page.IsPostBack.

Monday, 28 April, 2008 3 comments

Page.IsPostBack is for forms that are runat=”server”. It is mostly used for same page validation, same page operations, … anything really same page!

It is also used to help keep bandwidth and rendering times down.

The main reason why people use IsPostBack is to stop taping the databases everytime a request is made. If you are on your default page and just do work via that page, you can use the if Not page.ispostback then statements to populate information. When pages are posted back to the sever and then rendered back to the client, they don’t have the need to repopulate the information since it was just populated. It is all kept in the viewstate and read back without using precious resources on the server.

Read more…

Categories: ASP.NET 2.0 Tags:

Getting Visitor’s IP Address and Server’s IP Address

Thursday, 24 April, 2008 4 comments

Getting Visitors IP Address:

There are two ways, either by using:

The Following Line will get the IP Address of the machine instead of Proxy’s IP


Getting Server’s IP address:

string strHostName = Dns.GetHostName ();
IPHostEntry ipEntry = Dns.GetHostByName (strHostName);
IPAddress [ ] addr = ipEntry.AddressList;
for(int i=0;i< addr.Length;i++)
lblServerIP.Text=lblServerIP.Text+"The Server IP address is"+addr[i].ToString()+"\n";

Categories: ASP.NET 2.0, C# Tags: ,

Fill DropDownLists

Thursday, 24 April, 2008 Leave a comment

void FillDropDownLists()
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);
SqlCommand commGetDept = new SqlCommand("select id, dept from s_dept where id in (select dept from s_users) order by dept", conn);
SqlDataReader res = commGetDept.ExecuteReader();
ListDepts.DataTextField = "dept";
ListDepts.DataValueField = "id";
ListDepts.DataSource = res;
ListDepts.Items.Insert(0, "Все");
catch (SqlException sqlex)
//ErrMess.Text = sqlex.Message;
if (conn.State != ConnectionState.Closed) conn.Close();