ASP.NET

How to get site name in ASP.NET

You could get the IIS site name using the GetSiteName method.

System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName(); 

The GetSiteName is introduced in the .NET Framework …

Learn more

How to create Web Service in ASP.NET

In this tutorial you will use Visual Studio to create a new web service and then add methods to expose the functionality required for your web service.

To create the new Web Service:

On the Visual Studio 2010 file menu, choose New Project.

From drop down list .NET Framework choose .NET Framework 2.0.

Picture 1. How to create Web Service …

Learn more

How to upload file in ASP.NET

You could upload a file on the hosting server using the following C# code:

String sPath = Server.MapPath(“UploadFolder”);

String sFileName = “YourFileName.txt”

File.SaveAs(sPath + sFilename);

Right-click on the folder (UploadFolder folder), and then select Properties. In the Properties dialog box, click on the Security tab and make sure the ASP.NET Machine Account is included in the list and has the proper permissions to …

Learn more

How to open popup window in ASP.NET

1. Write the following ASP.NET code in the code behind file:

void Page_load(object sender, EventArgs e)
{
Button1.Attributes.Add( “onclick”, “popWindow()” );
}

2. The .aspx page shoud contains popup JavaScript function:

<html>
<head>
<script>
function popWindow(){
window.open(‘https://www.yourdomain.com/yourpage.aspx’, ”, ”);”);
}
</script>
</head>
<body>
<form runat=”server”>
<asp:Button id=”Button1″ onclick=”Button1_Click” runat=”server” Text=”Run”></asp:Button>
</form>
</body>
</html>

When you click on the button the new popup Window will appear with the desired …

Learn more

How to call JavaScript from ASP.NET code behind

To call JavaScript from C# code behind you should:

1. Set the Body tag in your page/master page to runat=”server” and an id=”MyBody”.
2. Code the script tag in your page:

<script src=”MyFunction.js” type=”text/javascript”></script>

3. In the code behind attach the onload attribute to the body tag:

protected void Page_Load(object sender, EventArgs e)
{
MasterPageBodyTag = …

Learn more

How to refresh a page in ASP.NET

To refresh or redirect ASP.NET page to another web page you should use the Refresh META tag:

<META HTTP-EQUIV=”Refresh” CONTENT=”5;url=https://yourURL” />

In this case the web page will be refreshed/redirected after …

Learn more

How to get IP address in ASP.NET

Whenever a browser sends a request for a page, it also sends a number of other headers to the script, containing information such as the browser type. It also includes information such as the visitors IP address.

In ASP.NET you can get the IP address of your users from the Request.ServerVariables collection. The following ASP.NET code will display the …

Learn more