How to Create Database connection in the Web.config file
Connection string in asp.net c#. In Asp.net there is an easier way give the Connection String.We can add more than one Connection String in the web.config file.Then we can access these Connection Strings in any of our Pages.This is a simply superb concept in Asp.net.
For example,you have two connection strings one for your local server and another one for your live server.You simply add these two Connections in the web.config file and access the first connection in one page and in another page you can use the next connection.
ok, how to save this?
Well,Programming with C# is very easier when compared to other languages.give the coding below in your web.config file, in configuration section,
add the
<connectionStrings> <add name="Conn" connectionstring="server=.; database=Northwind;Integrated Security=True;"/> </connectionStrings>
what is server?
may be the server is your localhost or your web server,if localhost means you just give the '.' or if your server is web server means just give the web server address 'XXX.XX.XXX'.
what is database?
database is the collection of data stored in a system.Its having a unique name.
what is Integrated Security?
if you are working in localhost means you dont need to give your userid and password.you just give the Integrated Security=True.
if you are using a webserver means the connection string will be slightly change,
<connectionStrings> <add name="Conn" connectionstring="server=XXX.XXX.XX; database=Northwind;uid=yourserveruserid; pwd=yourserverpassword;/> </connectionStrings>
what is uid and pwd?
uid is the userID when the sql installation you will give the userid and password.those userid and password will give here.
then,next step how to access this in our .aspx.cs file
add this namespace
using System.Data.Sqlclient
then add this in
SqlConnection con=new SqlConnection (ConfigurationManager.ConnectionStrings["Conn"]. ConnectionString.ToString()); con.Open(); is used for connection opening con.Close(); is used for connection closing.
This is the way of accessing the Connection Strings in all the pages.
How to manage Form authentication and the authorization in the Web.config file.
Authentication is necessary to almost every application. ASP.NET brings different Authentication Providers to make the authentication process easier. Among them, Forms-based authentication is the most often used one. With Forms Authentication, we create a login form with the logic to validate a user and .NET will create a Cookie on successful validation which the application will check for on each client request.
Forms Authentication is configured in web.config,
<configuration>
<system.web>
<authentication mode="Forms"/>
</system.web>
</configuration>If we want to deny access to anonymous users, configure the Authorization section in the following manner,
<configuration>
<system.web>
<authentication mode="Forms"/>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>With Forms Authentication, we can configure the name of the cookie to use, the protection type, the URL to use for the loginUrl, the length of time(minutes) the cookie is in effect, and the path to use for the issued cookie. If no cookie name is specified, the default is .ASPXAUTH. The loginUrl is the location of the Login form and to which any unauthenticated requests for protected resources will be automatically redirected.
<configuration>
<system.web>
<authentication mode= "Forms">
< name="MyLoginCookie" loginUrl="MyLoginForm.aspx" protection="[All/None/Encryption/Validation]" timeout="30" path="/” />
</authentication>
</system.web>
</configuration>ASP.NET also allows us to define login credentials in the Web.config file and Authenticate against them using the Authenticate() method of the FormsAuthentication provider. Of course, we only consider this way if there is a relatively small number of users; or else we’d better authenticate a user against a database of user credentials.
<system.web>
<authentication mode="Forms">
<forms loginUrl="MyLoginPage.aspx">
<credentials passwordFormat="[Clear/SHA1/MD5]">
<user name="mary" password="msdyaredd" />
</credentials>
</forms>
</authentication>
</system.web>
</configuration>How we should configure the Web,config file according to the E-mail sending...
After the <system.web/> we should change following changes to the Web.config file
<system.net> <mailSettings> <smtp> <network host="Host name" port="25" userName="Username" password="password" /> </smtp> </mailSettings> </system.net>
How to set the Image path when uploading images to the web..
<appSettings> <add key="ItemImagePath" value="Specify the path to save emages"/> </appSettings >
How to upload a larger size file into the web server...
additionally we have to configure the Web.config file as follows.
<httpRuntime executionTimeout="90" maxRequestLength="4096" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
No comments:
Post a Comment