how to upload an excel in c# ASP.Net?
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fuUpload.HasFile)
{
string filename = fuUpload.PostedFile.FileName;
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
+"Data Source="+ filename +";" +"Extended Properties=Excel
8.0;";
OleDbConnection con = new OleDbConnection(strConn);
con.Open();
OleDbCommand cmd = new OleDbCommand("select *
from [Sheet1$]",con);
OleDbDataAdapter dad = new OleDbDataAdapter();
dad.SelectCommand = cmd;
DataSet ds= new DataSet();
dad.Fill(ds);
DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
con.Close();
}
}
Hosting ASP.NET Pages
Hosting ASP.NET pages locally through the ASP.NET Development Web Server has a number of advantages:
* Testing can be done while offline-Because the request from your browser is being directed to your own personal computer, you don’t need to be connected to the Internet to test your ASP.NET pages.
* It’s fast-Local requests are, naturally, much quicker than requests that must travel over the Internet.
* Advanced debugging features are available-By developing locally, you can use advanced debugging techniques, such as halting the execution of an ASP.NET page and stepping through its code line-by-line.
* It’s secure-The ASP.NET Development Web Server allows only local connections. With this lightweight web server, you don’t need to worry about hackers gaining access to your system through an open website.
The main disadvantage of hosting ASP.NET pages locally is that they can be viewed only from your computer. That is, a visitor on another computer cannot enter some URL into her browser’s Address bar that will take her to the ASP.NET website you’ve created on your local computer. If you want to create an ASP.NET website that can be visited by anyone with an Internet connection, you should consider using a web-hosting company.
Web-hosting companies have a number of Internet-accessible computers on which individuals or companies can host their websites. These computers contain web servers that are accessible from any other computer on the Internet. Hour 24, “Deploying Your Website,” explores how to move an ASP.NET website from your personal computer to a web-hosting company’s computers. After a website has been successfully deployed to a web-hosting company, you, or anyone else on the Internet, can visit the site.
Explain the ways of authentication techniques in ASP.NET
Selection of an authentication provider is done through the entries in the web.config file for an application.
The modes of authentication are:
<authentication mode=”windows”>
<authentication mode=”passport”>
<authentication mode=”forms”>
Custom authentication needs installation of ISAPI filter in IIS. It compares incoming requests to a list of source IP addresses and a request is considered to be authenticated if it comes from an acceptable address.
What is Authentication in ASP.NET?
The process of identifying a user through the use of an ID and a password is known as Authentication.
The ASP.Net authentication providers are as follows:
Windows Authentication Provider:
It is in conjunction with Microsoft Internet Information Services (IIS) authentication to secure ASP.NET applications
Forms Authentication Provider
It is an application-specific login form which performs authentication using user code.
Passport Authentication provider:
It is a centralized authentication service provided by Microsoft that offers a single login and core profile service for member sites.
Describe how the ASP.NET authentication process works
ASP.NET runs inside the process of IIS due to which there are two authentication layers which exist in the system.
First authentication happens at the IIS level and the second at ASP.NET level per the WEB.CONFIG file.
Working:
At first, IIS ensures that the incoming request is from an authenticated IP address.
Otherwise the request is rejected.
By default IIS allows anonymous access due to which requests are automatically authenticated.
However, if this is changed, IIS performs its own user authentication too.
ASP.net checks if impersonation is enabled if a request is passed to ASP.net by an authenticated user. If it is enabled, ASP.net acts itself as an authenticated user else it acts with its own configured account.
Finally the OS resources are requested by the identity obtained from previous step.
The user is granted the resources if the authentication is successful else the resources are denied.
Resources can include ASP.net page, code access security features to extend authorization step to disk files, registry keys, etc.