<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Anas Ghanem </title><link>https://weblogs.asp.net:443/anasghanem/</link><description>All about ASP.NET</description><item><title>Microsoft Community Contributor Award for year 2011</title><link>https://weblogs.asp.net:443/anasghanem/microsoft-community-contributor-award-for-year-2011</link><description>&lt;a href="http://www.microsoftcommunitycontributor.com/" mce_href="http://www.microsoftcommunitycontributor.com/"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/anasghanem/Media/MCC11_Logo_Horizontal_Full-color.jpg" mce_src="https://aspblogs.blob.core.windows.net/media/anasghanem/Media/MCC11_Logo_Horizontal_Full-color.jpg" align="right"&gt;&lt;/a&gt;
&lt;p&gt;Today I was very surprised when I found an email from Microsoft awarding me one of the Community Contributor awards.This is really great and I would like to thank Microsoft for honoring me with such an award!&lt;/p&gt;&lt;p&gt;I hope I can help and contribute more on Microsoft forums and especially on the &lt;a href="http://forums.asp.net/" mce_href="http://forums.asp.net/"&gt;ASP.NET forums&lt;/a&gt;.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Thanks Microsoft!&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Thu, 28 Apr 2011 22:04:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/microsoft-community-contributor-award-for-year-2011</guid><category>community News</category></item><item><title>You may get "A potentially dangerous Request.QueryString value was detected from the client" after upgrading to ASP.NET 4</title><link>https://weblogs.asp.net:443/anasghanem/you-may-get-quot-a-potentially-dangerous-request-querystring-value-was-detected-from-the-client-quot-after-upgrading-to-asp-net-4</link><description>&lt;P mce_keep="true"&gt;I was upgradting one of the DNN portals to ASP.NET 4.After Upgrading completed and when i configured it to run under asp.net 4 in iis, I started to get that exception on every postback.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The mentioned exception is happening because in ASP.NET 4, the request validation is now being called for every asp.net resource like web services and other httphandlers.As a result, you may get that exception even if you turned off the RequestValidation via: &amp;lt;pages validateRequest="false" .... section.&lt;/P&gt;
&lt;P mce_keep="true"&gt;This is one of the breaking changes that were mentioned &lt;A href="http://www.asp.net/Learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770147" mce_href="http://www.asp.net/Learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770147"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;So the solution is to set the new HttpRuntime "&lt;A href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestvalidationmode.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestvalidationmode.aspx"&gt;RequestValidationMode&lt;/A&gt;" property to "2.0" and it should take care of that exception.&lt;/P&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;
&lt;P&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;&lt;FONT color=#a31515 size=2 face=Consolas&gt;httpRuntime&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2 face=Consolas&gt;&lt;FONT color=#ff0000 size=2 face=Consolas&gt;&lt;FONT color=#ff0000 size=2 face=Consolas&gt;requestValidationMode&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;2.0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2 face=Consolas&gt;&lt;FONT size=2 face=Consolas&gt;"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt;&lt;FONT color=#0000ff size=2 face=Consolas&gt; /&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Mon, 10 May 2010 13:54:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/you-may-get-quot-a-potentially-dangerous-request-querystring-value-was-detected-from-the-client-quot-after-upgrading-to-asp-net-4</guid><category>ASP.NET</category><category>ASP.NET 4</category></item><item><title>.NET Framework 4 Migration Issues</title><link>https://weblogs.asp.net:443/anasghanem/net-framework-4-migration-issues</link><description>&lt;p&gt;Before you start the migration, i suggest to read .NET 4 migration issues and breaking changes which can be found &lt;a href="http://msdn.microsoft.com/en-us/library/ee941656.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ee941656.aspx"&gt;&lt;b&gt;here&lt;/b&gt;&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Mon, 26 Apr 2010 17:00:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/net-framework-4-migration-issues</guid><category>.NET 4</category><category>ASP.NET</category></item><item><title>Wow ! “Add reference” dialog in VS 2010 is showing up quickly</title><link>https://weblogs.asp.net:443/anasghanem/wow-add-reference-dialog-in-vs-2010-is-showing-up-quickly</link><description>&lt;p&gt;I just wanted to mention that one of the cool enhancements in VS 2010 is that the “Add reference “ dialog will show up quickly and will load the assemblies on demand.&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Thanks For VS team for this enhancement !&lt;/p&gt;</description><pubDate>Sat, 24 Apr 2010 15:55:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/wow-add-reference-dialog-in-vs-2010-is-showing-up-quickly</guid><category>.NET 4</category><category>ASP.NET</category><category>Visual Studio</category></item><item><title>Solving “The Select operation is not supported by .. unless the SelectMethod is specified.”</title><link>https://weblogs.asp.net:443/anasghanem/solving-the-select-operation-is-not-supported-by-unless-the-selectmethod-is-specified</link><description>
&lt;p&gt;In most cases, You will get that error when you are using a data source control(like ObjectDataSource) without setting it’s SelectMethod&amp;nbsp; as data source for the DetailsView control.&lt;/p&gt;
  
&lt;p&gt;If you want to display&amp;nbsp; one record in the detailsView control to allow the user to edit it, then you should set the SelectMethod for the DataSource control,otherwise the detailsView control will not be able to get the record from the underlying datasource.&lt;/p&gt;
  
&lt;p&gt;But what if you are only using the DetailsView for only inserting the records; in that case, you will need to set the DetailsView DefaultMode property to “Insert” and also you will need to set it’s AutoGenerateRows to "false" because by default the detaisView will try to execute the select method of it’s underlying datasource to generate the columns/fields dynamically for you.&lt;/p&gt;
  
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
  
&lt;p&gt;Hope it helps.&lt;/p&gt;
  
&lt;p&gt;Anas&lt;/p&gt;
&lt;a href="http://dotnetshoutout.com/Solving-The-Select-operation-is-not-supported-by-unless-the-SelectMethod-is-specified" rev="vote-for" mce_href="http://dotnetshoutout.com/Solving-The-Select-operation-is-not-supported-by-unless-the-SelectMethod-is-specified"&gt;&lt;img src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fanasghanem%2Farchive%2F2010%2F04%2F20%2Fsolving-the-select-operation-is-not-supported-by-unless-the-selectmethod-is-specified.aspx" alt="Shout it" mce_src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fanasghanem%2Farchive%2F2010%2F04%2F20%2Fsolving-the-select-operation-is-not-supported-by-unless-the-selectmethod-is-specified.aspx" style="border: 0px none;"&gt;&lt;/a&gt;</description><pubDate>Tue, 20 Apr 2010 18:38:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/solving-the-select-operation-is-not-supported-by-unless-the-selectmethod-is-specified</guid><category>ASP.NET</category></item><item><title>Tip of the day: Don’t misuse the Link button control</title><link>https://weblogs.asp.net:443/anasghanem/tip-of-the-day-don-t-misuse-the-link-button-control</link><description>&lt;p&gt;Misuse ? Yes it is !&lt;/p&gt;
  
&lt;p&gt;I have seen a lot of developers who are using the &lt;a href="http://msdn.microsoft.com/en-us/library/1cd4z1zs%28VS.71%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/1cd4z1zs%28VS.71%29.aspx"&gt;LinkButton&lt;/a&gt; to do redirection only ! &lt;/p&gt;
  
&lt;p&gt;They are handling it’s click event to just write &lt;a href="http://msdn.microsoft.com/en-us/library/ms524309%28VS.90%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms524309%28VS.90%29.aspx"&gt;Response.Redirect&lt;/a&gt;("url”) like this:&lt;/p&gt;
  &lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e461b520-a877-4a78-810f-4717491ab0e9" class="wlWriterSmartContent"&gt; &lt;div style="border: 1px solid rgb(0, 0, 128); color: rgb(0, 0, 0); font-family: 'Courier New',Courier,Monospace; font-size: 10pt;"&gt; &lt;div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); max-height: 300px; overflow: auto;"&gt; 
&lt;ol style="background: none repeat scroll 0% 0% rgb(255, 255, 255); margin: 0pt 0pt 0pt 2em; padding: 0pt 0pt 0pt 5px;"&gt; 
&lt;li&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; LinkButton1_Click(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e)&lt;/li&gt;
 
&lt;li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"&gt;{&lt;/li&gt;
 
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Redirect(&lt;span style="color: rgb(163, 21, 21);"&gt;"~/ForgotPassword.aspx"&lt;/span&gt;);&lt;/li&gt;
 
&lt;li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"&gt;}&lt;/li&gt;
 &lt;/ol&gt;
 &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  
&lt;p&gt;Ok so to understand why it’s not a good practice let’s discuss the redirection steps involved when using the mentioned method:&lt;/p&gt;
  
&lt;ol&gt;   
&lt;li&gt;User submits the page by clicking on the LinkButton control.&lt;/li&gt;
    
&lt;li&gt;The LinkButton click event is fires which will cause the execution of Respose.Redirect.&lt;/li&gt;
    
&lt;li&gt;When the server code executes Response.Redirect, it will send redirection request for the browser.&lt;/li&gt;
    
&lt;li&gt;Browser understand the redirection message and issue a new request for “ForgotPassword.aspx” page.&lt;/li&gt;
    
&lt;li&gt;Server receive the request and send back the “ForgotPassword.aspx” to the browser.&lt;/li&gt;
 &lt;/ol&gt;
  
&lt;p&gt;As you can see, using Response.Redirect involves a lot of requests which can be avoided if you only use a HyperLink control like this:&lt;/p&gt;
  &lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1686c9a3-af00-4c9e-b616-1618e76ec63f" class="wlWriterSmartContent"&gt; &lt;div style="border: 1px solid rgb(0, 0, 128); color: rgb(0, 0, 0); font-family: 'Courier New',Courier,Monospace; font-size: 10pt;"&gt; &lt;div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); max-height: 300px; overflow: auto;"&gt; 
&lt;ol style="background: none repeat scroll 0% 0% rgb(255, 255, 255); margin: 0pt 0pt 0pt 2em; padding: 0pt 0pt 0pt 5px;"&gt; 
&lt;li&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;asp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;HyperLink&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ID&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="hypForgotPassword"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;runat&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="server"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;NavigateUrl&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="~/ForgotPassword.aspx"&amp;gt;&lt;/span&gt;&lt;/li&gt;
 
&lt;li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"&gt; Forgot your password?&lt;/li&gt;
 
&lt;li&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;asp&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;HyperLink&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt;
 &lt;/ol&gt;
 &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  
&lt;p&gt;This way, when the user click “Forgot password?” link, the browser will just request the “ForgotPassword.aspx” page,Hence it will skip step 1,2,3 and just go through step 4 and 5.&lt;/p&gt;
  
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
  
&lt;p&gt;&lt;b&gt;Summary:&lt;/b&gt;If you want to do redirection without doing any server side calculation, you can avoid all of the mentioned&amp;nbsp; extra requests by using the HyperLink control instead of the LinkButton or the standard Button control.&lt;/p&gt;
  
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
  
&lt;p&gt;Hope it helps.&lt;/p&gt;
  
&lt;p&gt;Anas&lt;/p&gt;&lt;a href="http://dotnetshoutout.com/Tip-of-the-day-Dont-misuse-the-Link-button-control-Anas-Ghanem" rev="vote-for"&gt;&lt;img src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fanasghanem%2Farchive%2F2010%2F04%2F20%2Ftip-of-the-day-don-t-misuse-the-link-button-control.aspx" alt="Shout it" style="border: 0px none;"&gt;&lt;/a&gt;
</description><pubDate>Mon, 19 Apr 2010 22:09:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/tip-of-the-day-don-t-misuse-the-link-button-control</guid><category>ASP.NET</category></item><item><title>Helper class to dynamically modify the Location configuration element</title><link>https://weblogs.asp.net:443/anasghanem/helper-class-to-dynamically-modify-the-location-configuration-element</link><description>&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/b6x6shw7.aspx"&gt;location element&lt;/a&gt; is used to restrict user or role access on a specific path.The path could be a folder,aspx page,ashx,axd or any other file that is handled by ASP.NET runtime.&lt;/p&gt;  &lt;p&gt;In most cases, you use that element declarativley in the web.config file of your website.In this case, you are declaratively telling the ASP.NET runtime and specifically the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.security.urlauthorizationmodule.aspx"&gt;UrlAuthorizationModule&lt;/a&gt; or the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.security.fileauthorizationmodule.aspx"&gt;FileAuthorizationModule&lt;/a&gt;(depending on the Authentication Mode) to grant/deny the access to that path for the specified users/roles.&lt;/p&gt;  &lt;p&gt;Sometimes, you will need to allow the administrator to change that using some setting screen and without touching the webiste files, in that case , you will have two options:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;If you can live with the application restarts , then you can using the Configuration class to modify location element using the code.I will show you how to do that using my Helper class. &lt;/li&gt;    &lt;li&gt;Depending on your site,if you don’t think that it’s ok to restart the application every time you modify the location element using that screen, then you can rollout your custom HttpModule and you could handle one of it’s events like AuthenticateRequest to intercept the incoming request and depending on some database table , you decide if that user is allowd to see that path. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In this post, i will assume that you chose the first option and decided to modify the location element dynamically.&lt;/p&gt;  &lt;p&gt;Since i had to do it myself, i decided to create a Helper class that can be used to allow/deny a specific user/role on the given virtualPath.&lt;/p&gt;  &lt;p&gt;Class in c#:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cb93fdac-a72d-4e94-b4c1-021d2e1b041f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 3em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;LocationElementHelper&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Configuration&lt;/span&gt; LocationElementConfiguration = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af"&gt;AuthorizationSection&lt;/span&gt; _AuthorizationSection = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; _configPath = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; _path = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; LocationElementHelper(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; webconfigVirtualPath, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; locationElementPath)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        _configPath = webconfigVirtualPath;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        _path = locationElementPath;&lt;/li&gt; &lt;li&gt;        PopulateInternalVariables();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; PopulateInternalVariables()&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Configuration&lt;/span&gt; config = &lt;span style="color:#2b91af"&gt;WebConfigurationManager&lt;/span&gt;.OpenWebConfiguration(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;._configPath);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (config.Locations.Count == 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;There is no location element in the specified web.config file&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;ConfigurationLocation&lt;/span&gt; loc &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; config.Locations)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (loc.Path.Equals(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;._path, &lt;span style="color:#2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase))&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                LocationElementConfiguration = loc.OpenConfiguration();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                _AuthorizationSection = (&lt;span style="color:#2b91af"&gt;AuthorizationSection&lt;/span&gt;)LocationElementConfiguration.GetSection(&lt;span style="color:#a31515"&gt;&amp;quot;system.web/authorization&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (_AuthorizationSection == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;Unable to locate the given Location element path in the specified web.config&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddUserToPath(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt; action)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; targetRule = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; authRule &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; _AuthorizationSection.Rules)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (authRule.Action == action)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                targetRule = authRule;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// not fund , we add it.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            targetRule = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt;(action);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// add  the user&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!targetRule.Users.Contains(userName))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            targetRule.Users.Add(userName);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        LocationElementConfiguration.Save();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; AddRoleToPath(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; roleName, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt; action)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; targetRule = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; authRule &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; _AuthorizationSection.Rules)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (authRule.Action == action)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                targetRule = authRule;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// not found , we add it.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            targetRule = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt;(action);&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// add the role&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!targetRule.Roles.Contains(roleName))&lt;/li&gt; &lt;li&gt;            targetRule.Roles.Add(roleName);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        LocationElementConfiguration.Save();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RemoveUserFromPath(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt; action)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; targetRule = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; authRule &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; _AuthorizationSection.Rules)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (authRule.Action == action)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                targetRule = authRule;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// not found, we do nothing&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// remove the user&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule.Users.Contains(userName))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            targetRule.Users.Remove(userName);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// if the Rule has no more users/roles , we remove it.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule.Roles.Count == 0 || targetRule.Users.Count == 0)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            _AuthorizationSection.Rules.Remove(targetRule);&lt;/li&gt; &lt;li&gt;        &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        LocationElementConfiguration.Save();&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RemoveRoleFromPath(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; roleName, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt; action)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; targetRule = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;AuthorizationRule&lt;/span&gt; authRule &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; _AuthorizationSection.Rules)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (authRule.Action == action)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            {&lt;/li&gt; &lt;li&gt;                targetRule = authRule;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;break&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// not found , we do nothing&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// remove the role&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule.Roles.Contains(roleName))&lt;/li&gt; &lt;li&gt;            targetRule.Roles.Remove(roleName);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// if the Rule has no more users/roles , we remove it.&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (targetRule.Roles.Count == 0 || targetRule.Users.Count == 0)&lt;/li&gt; &lt;li&gt;            _AuthorizationSection.Rules.Remove(targetRule);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        LocationElementConfiguration.Save();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Assuming that we have the following location elements in web.config file:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:85b3a59f-ce85-474c-8192-eec9665eda72" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;path&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;admin&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;allow&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;users&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;user1&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;path&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;acct&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;deny&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;users&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;user1&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;allow&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt;roles&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;Accountants&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;To add access to the administrators role on the admin path:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d0829ee2-eecc-4d71-858e-e1e6581f8cd7" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;LocationElementHelper&lt;/span&gt; helper = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;LocationElementHelper&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;~/&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;admin&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  helper.AddRoleToPath(&lt;span style="color:#a31515"&gt;&amp;quot;administrators&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt;.Allow);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;After executing the mentioned code, the admin location will become:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:87a801c3-e605-4618-9c71-7f7aa73bbed9" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;path&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;admin&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;allow&lt;/span&gt;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;users&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;user1&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; &lt;/span&gt;&lt;span style="color:#ff0000"&gt;roles&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt;administrators&lt;/span&gt;&amp;quot;&lt;span style="color:#0000ff"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;authorization&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;system.web&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;location&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Another example about removing the &amp;lt;deny users=”user1” /&amp;gt; from the acct.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7ffceb15-b536-400f-8f76-8f2ba502da55" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt; &lt;span style="color:#2b91af"&gt;LocationElementHelper&lt;/span&gt; helper = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;LocationElementHelper&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;~/&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;acct&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        helper.RemoveUserFromPath(&lt;span style="color:#a31515"&gt;&amp;quot;user1&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;AuthorizationRuleAction&lt;/span&gt;.Deny);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;  &lt;p&gt;Anas&lt;/p&gt;  &lt;br /&gt;&lt;a href="http://dotnetshoutout.com/Helper-class-to-dynamically-modify-the-Location-configuration-element-Anas-Ghanem" rev="vote-for"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fweblogs.asp.net%2Fanasghanem%2Farchive%2F2010%2F03%2F13%2Fhelper-class-to-dynamically-modify-the-location-configuration-element.aspx" /&gt;&lt;/a&gt;</description><pubDate>Fri, 12 Mar 2010 22:09:05 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/helper-class-to-dynamically-modify-the-location-configuration-element</guid><category>ASP.NET</category></item><item><title>Automatic creation of membership users and saving the result to csv file</title><link>https://weblogs.asp.net:443/anasghanem/automatic-creation-of-membership-users-and-saving-the-result-to-csv-file</link><description>&lt;p&gt;While working with Membership and roles providers, you may need to create the users based on your data and give them a random password.For example, you may have a table with customers and you want to give each customer a user/password to login to your system. &lt;/p&gt;  &lt;p&gt;You can manually create a user for each of your customers, but sometimes you will need to automate the process especially when : &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;You don’t want to enable public user registration. &lt;/li&gt;    &lt;li&gt;You have a large set of customers ( or whatever type of stakeholders you have), and you don't want to create a user to each of them manually. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I just did an example which create a user for each customer (based on the customer id ), and then save all the generated users and their passwords in a csv file. &lt;/p&gt;  &lt;p&gt;You may ask &lt;em&gt;“why i need the csv file, i can go to the database and get the generated users&lt;/em&gt;”.The problem here is that by default the membership will store the passwords in hashed format and so you will not be able to know the actual password that was assigned to the user when calling &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx"&gt;Membership.GeneratePassword&lt;/a&gt; method.Of course,you can change the membership settings to store the passwords in clear format, this way you can go directly to the membership tables in your database. &lt;/p&gt;  &lt;p&gt;The code that will create the users is simple:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateUsers()&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="rem"&gt;//FileStream to the CSV file that will holds the genrated users&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="rem"&gt;//in this example, the csv file will be placed in app_data folder, but you may want to change that location...&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        System.IO.FileStream fs = System.IO.File.Open(Server.MapPath(&lt;span class="str"&gt;&amp;quot;~/App_Data/users.csv&amp;quot;&lt;/span&gt;), System.IO.FileMode.OpenOrCreate);&lt;/pre&gt;

  &lt;pre&gt;        System.IO.StreamWriter sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.IO.StreamWriter(fs, Encoding.UTF8);&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// write the header of the csv file&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        sw.WriteLine(&lt;span class="str"&gt;&amp;quot;Customer name,UserName,Password&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;        List&amp;lt;Customer&amp;gt; customers = Customer.GetAllCustomers();&lt;/pre&gt;

  &lt;pre&gt; &lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; customers)&lt;/pre&gt;

  &lt;pre&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; password = Membership.GeneratePassword(10, 3);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            MembershipCreateStatus status = &lt;span class="kwrd"&gt;new&lt;/span&gt; MembershipCreateStatus();&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; customerUserName = GetCustomerUserName(c);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="rem"&gt;// you may need to generate the security questiomn/answer based on the customers data ?&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="rem"&gt;//or maybe disable the question/answer through mebership section in web.config and just pass null for both question and answer.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            MembershipUser muser = Membership.CreateUser(customerUserName, password, c.Email, &lt;span class="str"&gt;&amp;quot;security question here&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;security asnwer&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; status);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (status == MembershipCreateStatus.Success)&lt;/pre&gt;

  &lt;pre&gt;            {&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &lt;span class="rem"&gt;// add the user to customers role.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                Roles.AddUserToRole(muser.UserName, &lt;span class="str"&gt;&amp;quot;customer&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &lt;span class="rem"&gt;// write the created user to csv file&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                sw.WriteLine(c.CustomerName + &lt;span class="str"&gt;&amp;quot;,&amp;quot;&lt;/span&gt; + muser.UserName + &lt;span class="str"&gt;&amp;quot;,&amp;quot;&lt;/span&gt; + password);&lt;/pre&gt;

  &lt;pre class="alt"&gt;            }&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &lt;span class="rem"&gt;// write to output window to dispaly the failed user&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;                Debug.WriteLine(&lt;span class="str"&gt;&amp;quot;user creation failed for customer&amp;quot;&lt;/span&gt; + c.CustomerName + &lt;span class="str"&gt;&amp;quot; reason: &amp;quot;&lt;/span&gt; + status.ToString());&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;        sw.Close();&lt;/pre&gt;

  &lt;pre&gt;        fs.Close();&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetCustomerUserName(Customer c)&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// just consider the customerId as the username , you can use customername or whatever you want&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; c.CustomerId;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The customer class:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Customer&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CustomerId&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        get;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        set;&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CustomerName&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        get;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        set;&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Address&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        get;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        set;&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Email&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        get;&lt;/pre&gt;

  &lt;pre&gt;        set;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    }&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;Customer&amp;gt; GetAllCustomers()&lt;/pre&gt;

  &lt;pre class="alt"&gt;    {&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="rem"&gt;// for the sake of demonstration, we just return a dummy list of customers &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Customer&amp;gt;() {&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer() { CustomerId = &lt;span class="str"&gt;&amp;quot;c1&amp;quot;&lt;/span&gt;, CustomerName = &lt;span class="str"&gt;&amp;quot;cusomter 1&amp;quot;&lt;/span&gt;, Address = &lt;span class="str"&gt;&amp;quot;address 1&amp;quot;&lt;/span&gt;,Email=&lt;span class="str"&gt;&amp;quot;Email@customer1company.com&amp;quot;&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer() { CustomerId = &lt;span class="str"&gt;&amp;quot;c2&amp;quot;&lt;/span&gt;, CustomerName = &lt;span class="str"&gt;&amp;quot;cusomter 2&amp;quot;&lt;/span&gt;, Address = &lt;span class="str"&gt;&amp;quot;address 2&amp;quot;&lt;/span&gt;,Email=&lt;span class="str"&gt;&amp;quot;Email@customer2company.com&amp;quot;&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer() { CustomerId = &lt;span class="str"&gt;&amp;quot;c3&amp;quot;&lt;/span&gt;, CustomerName = &lt;span class="str"&gt;&amp;quot;cusomter 3&amp;quot;&lt;/span&gt;, Address = &lt;span class="str"&gt;&amp;quot;address 3&amp;quot;&lt;/span&gt; ,Email=&lt;span class="str"&gt;&amp;quot;Email@customer2company.com&amp;quot;&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre class="alt"&gt;        };&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Anas Ghanem&lt;/p&gt;</description><pubDate>Sat, 02 Jan 2010 19:13:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/automatic-creation-of-membership-users-and-saving-the-result-to-csv-file</guid><category>ASP.NET</category><category>Security</category></item><item><title>Programmatically Modifying the HyperLinks in the DataPager control</title><link>https://weblogs.asp.net:443/anasghanem/programmatically-modifying-the-hyperlinks-in-the-datapager-control</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;As you know,the DataPager control can be used to Implement data paging in any data Control that implements the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.ipageableitemcontainer.aspx"&gt;&lt;strong&gt;IPageableItemContainer&lt;/strong&gt;&lt;/a&gt; interface&lt;strong&gt;.&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;For now,the only control that implements that interface(In .NET 3.5 sp1) is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.aspx"&gt;ListView&lt;/a&gt; ASP.NET control. &lt;/p&gt;  &lt;p&gt;By default the DataPager control will use the postback to pass the page index of the DataPager control. &lt;/p&gt;  &lt;p&gt;However,the DataPager&amp;#160; can be configured to use the QueryString to pass the PageIndex for the Paged control, this can be done by setting it’s “&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datapager.querystringfield.aspx"&gt;QueryStringField&lt;/a&gt;” property to the name of the Query string field that you want. &lt;/p&gt;  &lt;p&gt;Developers may use the QueryStringField option to when they want to : &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Implement outputCache for the ListView pages based on the QueryStringField,I explained this in &lt;a href="http://blog.anasghanem.com/post/Implementing-Outputcache-with-ListView-Paging.aspx"&gt;this post&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Implement a more user and SEO friendly Urls by using Url Rewriting. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You can implement Url Rewriting in asp.net by using the new Routing &lt;a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx"&gt;features&lt;/a&gt; which were introduced in ASP.NET 3.5. You can also use the &lt;a href="http://urlrewriter.net/"&gt;urlrewrite.net&lt;/a&gt; tool if you like. &lt;/p&gt;  &lt;p&gt;But when you will need to modify the Generated&amp;#160; Url in the page of DataPager control ? &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;When you use Url Rewriting, you will need to modify the Urls of the Pager HyperLink controls in a way that can work with your Url Rewriting scheme. &lt;/li&gt;    &lt;li&gt;By default,the DataPager control &lt;strong&gt;will not include the&lt;/strong&gt; SessionId in it’s HyperLinks when you use cookie less session mode.This of course will cause a session loss when you navigate through the ListView pages using the Pager &lt;/li&gt;    &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:94a5a960-8b03-4db2-86c7-264c19a5142b" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ListView" rel="tag"&gt;ListView&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DataPager" rel="tag"&gt;DataPager&lt;/a&gt;&lt;/div&gt;    &lt;li&gt;links.You can fix that by using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.applyapppathmodifier.aspx"&gt;Response.ApplyAppPathModifier&lt;/a&gt; function which will take the Url and correctly append the sessionId to it. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Modifying the HyperLink in the DataPager will only require to handle the ListView DataBound event and loop though the HyperLinks of the DataPager control:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt; &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ListView1_DataBound(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

  &lt;pre&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;        DataPager pager = ListView1.FindControl(&lt;span class="str"&gt;&amp;quot;DataPager1&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; DataPager;&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="rem"&gt;// this check is important to avoid touching the Hyperlinks if the Pager doesn't configured to use Query string Field&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty( pager.QueryStringField))&lt;/pre&gt;

  &lt;pre class="alt"&gt;        {&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (DataPagerFieldItem Pitem &lt;span class="kwrd"&gt;in&lt;/span&gt; pager.Controls)&lt;/pre&gt;

  &lt;pre class="alt"&gt;            {&lt;/pre&gt;

  &lt;pre&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Control c &lt;span class="kwrd"&gt;in&lt;/span&gt; Pitem.Controls)&lt;/pre&gt;

  &lt;pre class="alt"&gt;                {&lt;/pre&gt;

  &lt;pre&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (c &lt;span class="kwrd"&gt;is&lt;/span&gt; HyperLink)&lt;/pre&gt;

  &lt;pre class="alt"&gt;                    {&lt;/pre&gt;

  &lt;pre&gt;                        HyperLink tmp = c &lt;span class="kwrd"&gt;as&lt;/span&gt; HyperLink;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                        tmp.NavigateUrl = &lt;span class="str"&gt;&amp;quot;....&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;                    }&lt;/pre&gt;

  &lt;pre class="alt"&gt;                }&lt;/pre&gt;

  &lt;pre&gt;            }&lt;/pre&gt;

  &lt;pre class="alt"&gt;        }&lt;/pre&gt;

  &lt;pre&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Anas Ghanem. &lt;/p&gt;</description><pubDate>Thu, 08 Oct 2009 18:17:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/programmatically-modifying-the-hyperlinks-in-the-datapager-control</guid><category>ASP.NET</category></item><item><title>Request.Browser.Version is returning 7 when browsing with IE8</title><link>https://weblogs.asp.net:443/anasghanem/request-browser-version-is-returning-7-when-browsing-with-ie8</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;I noticed that some developers are getting the value 7 from &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.browser(VS.100).aspx"&gt;Request.Browser.Version&lt;/a&gt; property when testing the page with IE8. &lt;/p&gt;  &lt;p&gt;If you are one from those guys, then you are viewing the page in the IE8 “compatibility mode”.By using that mode, you are telling IE8 to behave as IE7. &lt;/p&gt;  &lt;p&gt;Regards, &lt;/p&gt;  &lt;p&gt;Anas Ghanem &lt;/p&gt;</description><pubDate>Wed, 26 Aug 2009 18:19:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/request-browser-version-is-returning-7-when-browsing-with-ie8</guid><category>ASP.NET</category></item><item><title>Adding custom properties to the Membership user , what are the options?</title><link>https://weblogs.asp.net:443/anasghanem/adding-custom-properties-to-the-membership-user-what-are-the-options</link><description>&lt;p&gt;One of a frequently asked questions is “how to add a custom columns/properties to the MembershipUser class?”. &lt;/p&gt;  &lt;p&gt;Based on my experience , there are many ways to do that : &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;You can use the user profile services to store those custom properties, article [&lt;strong&gt;&lt;a href="http://www.4guysfromrolla.com/articles/101106-1.aspx"&gt;here&lt;/a&gt;&lt;/strong&gt;]. &lt;/li&gt;    &lt;li&gt;Create a custom database table with a 1-1 relationship with the membership users table and handle the read/write operations on that custom table using ADO.NET or any other data access technology, article [&lt;a href="http://aspnet.4guysfromrolla.com/articles/070506-1.aspx"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;] &lt;/li&gt;    &lt;li&gt;Create a custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.aspx"&gt;MembershipUser&lt;/a&gt; that inherits the MembershipUser class and add the new properties.articles [&lt;a href="http://msdn.microsoft.com/en-us/library/ms366730.aspx"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;] and &lt;a href="http://www.asp.net/learn/videos/video-189.aspx"&gt;&lt;strong&gt;video&lt;/strong&gt;&lt;/a&gt;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;But which method is the best for you ? &lt;/p&gt;  &lt;p&gt;every method has proc/cons , i will list them all in the table below: &lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="663"&gt;&lt;tbody&gt;     &lt;tr style="background-color: #cccccc"&gt;       &lt;td valign="top" width="128"&gt;Storage method&lt;/td&gt;        &lt;td valign="top" width="272"&gt;Pros&lt;/td&gt;        &lt;td valign="top" width="261"&gt;Cons&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="128"&gt;User’s profile&lt;/td&gt;        &lt;td valign="top" width="272"&gt;Doesn’t require any additional code, just you need to declare the custom properties in web.config and you can then use the Profile class to read/write or manipulate these values&lt;/td&gt;        &lt;td valign="top" width="261"&gt;not suitable if you are going to display the user information via an external reporting tool like Reporting services.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="128"&gt;Custom database table&lt;/td&gt;        &lt;td valign="top" width="272"&gt;Very flexible and can be displayed using any external reporting tool.&lt;/td&gt;        &lt;td valign="top" width="261"&gt;Needs more work to handle the data access code and write some helper classes to manipulate the custom user properties.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="128"&gt;Custom MembershipUser and MembershipProvider&lt;/td&gt;        &lt;td valign="top" width="272"&gt;Cleaner,maintainable and flexible solution.Also integrates with the current Login controls.&amp;#160; &lt;br /&gt;&lt;/td&gt;        &lt;td valign="top" width="261"&gt;It needs more more effort because it will requires to write custom membershipUser and MembershipProvider …&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.anasghanem.com%2fpost%2fAdding-custom-properties-to-the-Membership-user-what-are-the-options.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.anasghanem.com%2fpost%2fAdding-custom-properties-to-the-Membership-user-what-are-the-options.aspx" width="82" height="18" /&gt;&lt;/a&gt;</description><pubDate>Fri, 14 Aug 2009 18:21:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/adding-custom-properties-to-the-membership-user-what-are-the-options</guid><category>ASP.NET</category></item><item><title>Getting the user Login date and time when using FormsAuthentication</title><link>https://weblogs.asp.net:443/anasghanem/getting-the-user-login-date-and-time-when-using-formsauthentication</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;When you want to get the user login date/time&amp;#160; you can follow one of the following ways : &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Through the user Ticket:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Get the current ticket of the logged in user and through it’s IssueDate property , you will get what you are looking for : &lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (HttpContext.Current.User.Identity &lt;span class="kwrd"&gt;is&lt;/span&gt; FormsIdentity)&lt;/pre&gt;

  &lt;pre&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="rem"&gt;// get the identity of the user&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="rem"&gt;// if authenticated , &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="rem"&gt;//get the login date/time which is exactly the same as the authentication ticket issue date.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (identity.IsAuthenticated)&lt;/pre&gt;

  &lt;pre class="alt"&gt;            {&lt;/pre&gt;

  &lt;pre&gt;                DateTime loginDate = identity.Ticket.IssueDate;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            }&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Through the membership Provider :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are using the Membership provider, you can get that user login date as follows: &lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (Request.IsAuthenticated)&lt;/pre&gt;

  &lt;pre&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;            MembershipUser muser = Membership.GetUser();&lt;/pre&gt;

  &lt;pre&gt;            DateTime LoginDate = muser.LastLoginDate;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;</description><pubDate>Fri, 17 Jul 2009 18:23:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/getting-the-user-login-date-and-time-when-using-formsauthentication</guid><category>ASP.NET</category></item><item><title>Do you have to migrate from .NET 2.0 Ajax extensions to .NET 3.5 Ajax ?</title><link>https://weblogs.asp.net:443/anasghanem/do-you-have-to-migrate-from-net-2-0-ajax-extensions-to-net-3-5-ajax</link><description>&lt;p&gt;While i was reading the unanswered posts on the forms.asp.net, i came across a post that asks about whether we should migrate to .NET 3.5 Ajax or just stay using the .NET 2.0 Ajax extensions? &lt;/p&gt;  &lt;p&gt;.NET 3.5 Ajax is better because it provided many additional features like script combining and Ajax history.Also,to be able to use the latest Ajax toolkit controls (like the &lt;a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HTMLEditor/HTMLEditor.aspx"&gt;HtmlEditor&lt;/a&gt;, &lt;a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx"&gt;Combobox&lt;/a&gt; and &lt;a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ColorPicker/ColorPicker.aspx"&gt;ColorPicker&lt;/a&gt;), you should be using .NET 3.5 Ajax features. &lt;/p&gt;  &lt;p&gt;My advice is to migrate as soon as possible because by keeping your self with .NET 2.0, you may get more limitations in the future. &lt;/p&gt;  &lt;p&gt;Migrating from .NET 2.0 to 3.5 may requires some little work.You have to take care of some breaking changes like &lt;a href="http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/"&gt;the new “d” character&lt;/a&gt;(that will prefix the json serialized objects in .NET 3.5) .Also you will have to make some changes in the registered Ajax dlls versions to use the new 3.5 Ajax extensions dlls.And if you are using Ajax toolkit for .net 2 , you will have to replace that Ajax toolkit dll with the suitable Ajax toolkit version for .NET 3.5 . &lt;/p&gt;  &lt;p&gt;The following are some resources on migrating your Ajax enabled sites/applications from .NET 2.0 to 3.5 : &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb907623.aspx"&gt;How To: Upgrade an ASP.NET AJAX 1.0 Web Project to .NET Framework 3.5.&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb907639.aspx"&gt;How To: Work with an ASP.NET AJAX 1.0 Web Project in Visual Studio 2008&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb907647.aspx"&gt;Walkthrough: Converting a Visual Studio 2005 Web Site Project to a Visual Studio 2008 Web Site Project.&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb907624.aspx"&gt;Walkthrough: Converting a Visual Studio 2005 Web Site Project to a Visual Studio 2008 Web Application Project&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb907783.aspx"&gt;Walkthrough: Converting a Visual Studio 2005 Web Application Project to a Visual Studio 2008 Web Application Project&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Regards, &lt;/p&gt;  &lt;p&gt;Anas Ghanem. &lt;/p&gt;</description><pubDate>Sat, 11 Jul 2009 19:08:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/do-you-have-to-migrate-from-net-2-0-ajax-extensions-to-net-3-5-ajax</guid><category>Ajax</category><category>ASP.NET</category></item><item><title>Applying custom styles for the GridView sorted Columns in .NET 4 beta1</title><link>https://weblogs.asp.net:443/anasghanem/applying-custom-styles-for-the-gridview-sorted-columns-in-net-4-beta1</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;Before .NET 4 ,when the developer wants to provide a custom style for the column that is currently sorted (like adding “sort arrow” in the header of the sorted column) , the developer was have to handle the GridView sorted event and apply some custom styles to that column, &lt;a href="http://aspnet.4guysfromrolla.com/articles/012308-1.aspx"&gt;see Scott Mitchell article&lt;/a&gt; for more information . &lt;/p&gt;  &lt;p&gt;.NET 4 beta 1 introduced a new styling features which allows the developers to specify a custom style&amp;#160; for the column that the data is sorted by. &lt;/p&gt;  &lt;p&gt;The following are a list of the new GridView properties which can be used to apply custom styles for the sorted columns: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortedascendingheaderstyle%28VS.100%29.aspx"&gt;SortedAscendingHeaderStyle&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorteddescendingcellstyle%28VS.100%29.aspx"&gt;SortedDescendingCellStyle&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortedascendingheaderstyle%28VS.100%29.aspx"&gt;SortedAscendingHeaderStyle&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorteddescendingheaderstyle%28VS.100%29.aspx"&gt;SortedDescendingHeaderStyle&lt;/a&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For more information , check the MSDN documentation [&lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd695835(VS.100,loband).aspx"&gt;here&lt;/a&gt;&lt;/strong&gt;]. &lt;/p&gt;  &lt;p&gt;Regards, &lt;/p&gt;  &lt;p&gt;Anas Ghanem. &lt;/p&gt;</description><pubDate>Fri, 10 Jul 2009 19:09:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/applying-custom-styles-for-the-gridview-sorted-columns-in-net-4-beta1</guid><category>.NET 4</category><category>ASP.NET</category></item><item><title>'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider' cannot be instantiated under a partially trusted security policy</title><link>https://weblogs.asp.net:443/anasghanem/system-data-entity-design-aspnet-entitydesignerbuildprovider-cannot-be-instantiated-under-a-partially-trusted-security-policy</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;After finishing one of the websites that were developed using &lt;a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx"&gt;Entity framework&lt;/a&gt; , I published&amp;#160; it to hosting company server.When i tried to open the newly published site, i got the following error: &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Parser Error Message: Type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider' cannot be instantiated under a partially trusted security policy (AllowPartiallyTrustedCallersAttribute is not present on the target assembly).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;After some investigation , I found that the mentioned error was caused by the following build Provider section that were placed in web.config by VS 2008: &lt;/p&gt;  &lt;p&gt;&amp;lt;buildProviders&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;add extension=&amp;quot;.edmx&amp;quot; type=&amp;quot;System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;lt;/buildProviders&amp;gt; &lt;/p&gt;  &lt;p&gt;The “EntityDesignerBuildProvider” class is contained in&amp;#160; System.Data.Entity.Design.dll which does not have the AllowPartiallyTrustedCallersAttribute and so any call to it in the partial trust will fail. &lt;/p&gt;  &lt;p&gt;when i removed the mentioned “buildProviders” section and refreshed the site, i got the following error: &lt;/p&gt;  &lt;p&gt;&lt;em&gt;The specified default EntityContainer name 'entity model name here' could not be found in the mapping and metadata information.      &lt;br /&gt;Parameter name: defaultContainerName.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;After that i started to think that removing the mentioned section prevented the complier from compiling the entity model. &lt;/p&gt;  &lt;p&gt;I think the problem is that since i didn’t precompiled the website and just copied it to the hosting server(using “copy website” option), the runtime will try to compile it dynamically (including the entity model “edmx&amp;quot; file) hence the first&amp;#160; mentioned error will occur. &lt;/p&gt;  &lt;p&gt;many solutions comes to my head, like pre-compiling the website to avoid dynamic compilations on the hosting server, or just moving the entity model from App_code to a separate class library project which allow me to only build the class library project and publish the dll to the website Bin directory. &lt;/p&gt;  &lt;p&gt;precompiling the website wasn’t an option for me because i know that i still need to apply partial updates to it and so i can’t re-upload the whole stuff every time i change something in the website. &lt;/p&gt;  &lt;p&gt;So i selected the second solution.I goes a head and moved the entity model file “edmx” from the website App_Code&amp;#160; to a separate class library project.then compiled entity model project and added it’s resulted dll to the website Bin directory. &lt;/p&gt;  &lt;p&gt;Problem solved :) &lt;/p&gt;  &lt;p&gt;Hope that help you ! &lt;/p&gt;</description><pubDate>Sat, 27 Jun 2009 19:12:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/system-data-entity-design-aspnet-entitydesignerbuildprovider-cannot-be-instantiated-under-a-partially-trusted-security-policy</guid><category>ASP.NET</category></item><item><title>Entity Framework:What’s new in .NET 4 and VS 2010</title><link>https://weblogs.asp.net:443/anasghanem/entity-framework-what-s-new-in-net-4-and-vs-2010</link><description>&lt;p&gt;For the list of updates and enhancements , checkout &lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/11/update-on-the-entity-framework-in-net-4-and-visual-studio-2010.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/11/update-on-the-entity-framework-in-net-4-and-visual-studio-2010.aspx"&gt;this post&lt;/a&gt; from ADO.NET team.&lt;/p&gt;</description><pubDate>Fri, 22 May 2009 13:15:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/entity-framework-what-s-new-in-net-4-and-vs-2010</guid><category>.NET 4</category><category>ASP.NET</category><category>News</category></item><item><title>Displaying the text that was originally stored using multi line TextBox</title><link>https://weblogs.asp.net:443/anasghanem/displaying-the-text-that-was-originally-stored-using-multi-line-textbox</link><description>&lt;p&gt;One common problem that face the developers is that when they store a text using Multiline text box ,and try to dispaly that text using the label ( or any other control) on the form, they will find that the line breaks and spaces is not being rendered with in the text. &lt;/p&gt;  &lt;p&gt;This is because the line break character in text box text is the .NET newline character which is “\n” or Envirnment.NewLine,and the same for the space which is “\t”.And since the browsers can’t understand those characters,they will not displayed in the rendered text. hence the rendered text will look messy. &lt;/p&gt;  &lt;p&gt;One simple solution is to replace those characters with there equivalent html tags that can be understood by the browsers. &lt;/p&gt;  &lt;p&gt;So the “\n” can be replaced by “&amp;lt;br/&amp;gt;” and the “\t” with “&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;”&amp;#160; ( three space characters in html). &lt;/p&gt;  &lt;p&gt;The .NET code for this could be :&lt;/p&gt;  &lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;string&lt;/span&gt; OrginalTextFromDataBase=TextBox1.Text;        
  Label1.Text = OrginalTextFromDataBase.Replace(&lt;span class="str"&gt;&amp;quot;\n&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;&amp;lt;br/&amp;gt;&amp;quot;&lt;/span&gt;).Replace(&lt;span class="str"&gt;&amp;quot;\t&amp;quot;&lt;/span&gt;,&lt;span class="str"&gt;&amp;quot;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;So, you don’t have to worry about the stored text , just format it correctly when you want to dispaly it as html. &lt;/p&gt;

&lt;p&gt;Note:If you want to dispaly the text in the textbox for further editing , then there is no need to replace those characters because the textbox control will recognize them. &lt;/p&gt;

&lt;p&gt;Anas Ghanem &lt;/p&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;</description><pubDate>Tue, 14 Apr 2009 19:14:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/displaying-the-text-that-was-originally-stored-using-multi-line-textbox</guid><category>ASP.NET</category></item><item><title>Microsoft Free Web Platform Installer (WEB PI)</title><link>https://weblogs.asp.net:443/anasghanem/microsoft-free-web-platform-installer-web-pi</link><description>&lt;p&gt;Web platform installer is a small application that allow you to stay update to date with the latest .NET tools,updates and additions that is being added to the framework.Developers may not have enough time to search and read the latest releases and updates.And so the purpose of this tool is to server as a “single-place” for the developers to check the last updates and new releases that is related to .NET and Microsoft tools in generals.&lt;/p&gt;  &lt;p&gt;So what you have to do is to &lt;a href="http://go.microsoft.com/fwlink/?LinkId=146697"&gt;install the “WEB PI”&lt;/a&gt; software and when you want to check the latest updates,tools and other stuff, you just need to open it and it will automatically update itself and show you the latest additions and tools.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;There is currently two versions from the software :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146697"&gt;Version 1&lt;/a&gt; : which provide the mentioned things. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=145510"&gt;Version 2( Beta):&lt;/a&gt; In addition to those things, this version also includes the popular open source asp.net projects(like DNN,Blog engine, ….) and also the PHP popular projects like(word press,wiki media …) which allow you to stay update with the latest updates and the latest releases of these projects. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope it helps.&lt;/p&gt;</description><pubDate>Mon, 13 Apr 2009 23:05:18 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/microsoft-free-web-platform-installer-web-pi</guid><category>.NET</category><category>ASP.NET</category><category>Tools</category></item><item><title>Did you know that there is a VS 2008 sp1 Offline installer</title><link>https://weblogs.asp.net:443/anasghanem/did-you-know-that-there-is-a-vs-2008-sp1-offline-installer</link><description>&lt;p&gt;Hi, &lt;/p&gt;  &lt;p&gt;If you tried to &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en"&gt;install VS 2008&lt;/a&gt; , you will notice the the download button will install a small exe file which will connect to Microsoft servers to install the sp1 using online mode. &lt;/p&gt;  &lt;p&gt;What i didn’t noticed is that there is a small note in the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en"&gt;download page&lt;/a&gt; which is under the instructions sections(one of my friends told me about it) , the note is : &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;“Note: this service pack is also available in &lt;/strong&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=122095"&gt;&lt;strong&gt;.iso format&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.”&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Which means that you can download the service pack as offline copy from the SP1 installer so that you don’t have to install the SP from the internet every time you need it.Also i find that the offline installer is more practical because my internet connection is not stable. &lt;/p&gt;  &lt;p&gt;Hope it help someone. &lt;/p&gt;</description><pubDate>Mon, 13 Apr 2009 19:17:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/did-you-know-that-there-is-a-vs-2008-sp1-offline-installer</guid><category>ASP.NET</category><category>Visual Studio</category></item><item><title>Birzeit university - Practical ASP.Net development session</title><link>https://weblogs.asp.net:443/anasghanem/birzeit-university-practical-asp-net-development-session</link><description>&lt;p&gt;Hi everyone. &lt;/p&gt;  &lt;p&gt;This will provide some information's about my second session in birzeit university. &lt;/p&gt;  &lt;p&gt;We announced for that session at&amp;#160; &lt;a href="http://paldev.net/blogs/announcements/archive/2009/04/03/birzeit-university-practical-asp-net-development.aspx"&gt;PalDev.NET announcements page&lt;/a&gt; .The session was held on Saturday, April 4, 2009 and was from 11:00 to 12:00 AM. During the session , i used the various asp.net features to build a fully workable website.I used the Master pages,Login controls, data controls and VS 2008 to build the site. &lt;/p&gt;  &lt;p&gt;The attendees was very Excited when they saw the power features of asp.net and VS 2008. &lt;/p&gt;  &lt;p&gt;This session was held as an activity of &lt;a href="http://www.paldev.net"&gt;PalDev.NET&lt;/a&gt; community, we in &lt;a href="http://www.paldev.net"&gt;PalDev.Net&lt;/a&gt; promise to give more advanced topics about the latest asp.net technologies. &lt;/p&gt;  &lt;p&gt;I attached the presentation slides. &lt;/p&gt;  &lt;p&gt;Best regards, &lt;/p&gt;  &lt;p&gt;Anas Ghanem. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://localhost/file.axd?file=2009%2f4%2fSession+2.pptx"&gt;Session 2.pptx (198.64 kb)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;img alt="" src="http://localhost/image.axd?picture=2009%2f4%2fbzulogo.jpg" width="500" height="250" /&gt;&lt;/p&gt;</description><pubDate>Fri, 10 Apr 2009 19:22:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/anasghanem/birzeit-university-practical-asp-net-development-session</guid><category>Presentations and Talks</category></item></channel></rss>