This is sample code to add keyword, description, and title from c#.net while using master page.
This code should be in .cs file and will be different for each page.
protected void Page_PreRender(object sender, EventArgs e)
{
HtmlMeta hMeta = new HtmlMeta();
hMeta.Name = "description";
hMeta.Content = "BharatClick Feedback, User comments, Reply Classifieds, Classifieds FAQ, Classifieds Help, Ad feedback, Ad Reply, Post new Ad, Classified software, Classified Review, Advance Classified, Classified list";
Page.Header.Controls.Add(hMeta);
hMeta = null;
hMeta = new HtmlMeta();
hMeta.Name = "keywords";
hMeta.Content = "BharatClick Feedback, User comments, Reply Classifieds, Classifieds FAQ, Classifieds Help, Ad feedback, Ad Reply, Post new Ad, Classified software, Classified Review, Advance Classified, Classified list";
Page.Header.Controls.Add(hMeta);
Page.Title = "BharatClick Feedback, User comments, Reply Classifieds, Classifieds FAQ, Classifieds Help, Ad feedback, Ad Reply, Post new Ad, Classified software, Classified Review, Advance Classified, Classified list ";
}
Adding security restrictions in ASP.NET pages using web.config
This is sample code to add security restriction to asp.net pages.
To give admin rights to “Admin” folder
<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrators"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
To restrict a webpage use
<location path="PostAd.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Full code for web.config
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrators"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<location path="PostAd.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="EditPhotos.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="MyAds.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="MyProfile.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.web>
<customErrors mode="Off"/>
<pages styleSheetTheme="Red"/>
<authentication mode="Forms"/>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
<profile enabled="true">
<properties>
<add name="FirstName" type="System.String"/>
<add name="LastName" type="System.String"/>
<add name="MemberId" defaultValue="0" type="System.Int32"/>
<group name="Core"/>
</properties>
</profile>
<roleManager enabled="true" />
<compilation debug="true">
<assemblies>
</assemblies>
</compilation>
<siteMap defaultProvider="RoleEnabled_AspNetXmlSiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="RoleEnabled_AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
</httpHandlers>
<httpModules>
<add name="URLRewrite" type="URLRewrite"/>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
<connectionStrings>
<add name="Connection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.net>
<mailSettings>
<smtp>
<network host="relay-hosting.secureserver.net" port="25" />
</smtp>
</mailSettings>
</system.net>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
</handlers>
</system.webServer>
</configuration>
0 comments:
Post a Comment