Large file uploads in ASP.NET
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.”
Difference between Page.IsPostBack and Not page.IsPostBack.
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.
[C#] Using the switch case Statement
The switch statement chooses flow of control based on the evaluation of a
numeric or string comparison.The switch statement does not allow control to fall
through to the next case as in C/C++ unless the case statement is followed
immediately by another case statement. In other words, you must use a break statement
with every case statement.You can also use a goto statement, although most
programmers frown on using them. Here are two examples:
int j = 0;
int i = 1;
switch (i)
{
case 1:j = 7;break;
case 2:
case 3:j = 22;break;
default:j = 33; break;
}
…
string lastName = “”;
string text = “fred”;
switch ( text )
{
case “fred”:lastName = “Flinstone”;break;
case “barney”:lastName = “Rubble”;break;
default:lastName = “Slate”;break;
}
Getting Visitor’s IP Address and Server’s IP Address
Getting Visitors IP Address:
There are two ways, either by using:
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
The Following Line will get the IP Address of the machine instead of Proxy’s IP
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
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";
}
Fill DropDownLists
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);
try
{
conn.Open();
SqlDataReader res = commGetDept.ExecuteReader();
ListDepts.DataTextField = "dept";
ListDepts.DataValueField = "id";
ListDepts.DataSource = res;
ListDepts.DataBind();
ListDepts.Items.Insert(0, "Все");
res.Close();
}
catch (SqlException sqlex)
{
//ErrMess.Text = sqlex.Message;
return;
}
catch
{
return;
}
finally
{
if (conn.State != ConnectionState.Closed) conn.Close();
}
}
Get data from web.config
Any data
——————————————————
store:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="admins" value="esetov_b, lobanov_v"/>
</appSettings>
...
get:
string admins = ConfigurationManager.AppSettings["Admins"];
Connection String
——————————————————
store
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ASPGConnectionString" connectionString="Data Source=DS;Initial Catalog=basename;Persist Security Info=True;User ID=user;Password=psw"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
...
get
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);
Selectable grid in ASP.NET 2.0 (Visually)
protected void Grid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.backgroundColor='#FFE4B5'";
e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='#FFFFFF'";
}
}
identification of domen user
string domen = HttpContext.Current.User.Identity.Name;
int pos = domen.IndexOf("\\");
string UserName = domen.Substring(pos + 1);
Navigator via Repeater
<asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink><asp:Repeater ID="Repeater1" runat="server" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
Recent Comments