I wrote a small ASP.NET application, which needed to read the web.config file. To open the Web.config file I used 'OpenWebConfiguration':
WebConfigurationManager.OpenWebConfiguration(...)
Since GoDaddy uses medium trust, I kept on getting:
'The application attempted to perform an operation not allowed by the security policy'
And in the detailed:
'System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
The resolution - use ConfigurationManager.ConnectionStrings instead.
Sunday, July 12, 2009
Monday, June 29, 2009
Pre-selecting items from CheckBoxList
I'm not much of an ASP.NET guy, but from time to time I've got to write some simple ASP.NET pages.
I've tried to use data-bound CheckBoxList (data binding done with the built-in wizard), and update the data with some pre-selected values. For some reason CheckBoxList Items are not populated when Page_Load function is called, so the list can't be updated.
Solution A: Found it on Google, but should have thought about it myself - just remove the data-binding done with the VS wizard, and do all the data handling in code.
Solution B (better): Call 'DataBind()' before pre-selecting the CheckBoxList items.
Weird. I must be missing something here. Anyway - it's working.
I've tried to use data-bound CheckBoxList (data binding done with the built-in wizard), and update the data with some pre-selected values. For some reason CheckBoxList Items are not populated when Page_Load function is called, so the list can't be updated.
Solution A: Found it on Google, but should have thought about it myself - just remove the data-binding done with the VS wizard, and do all the data handling in code.
Solution B (better): Call 'DataBind()' before pre-selecting the CheckBoxList items.
Weird. I must be missing something here. Anyway - it's working.
Labels:
ASP.NET
Tuesday, June 23, 2009
Generics Dictionary<> clone
Here's a simple routine that will clone generic Dictionary:
public static Dictionary<S, V> Clone<S,V>(Dictionary<S, V> dictionary)
{
Dictionary<S, V> cloneDictionary = new Dictionary<S, V>();
foreach (KeyValuePair<S, V> kvp in dictionary)
cloneDictionary.Add(kvp.Key, kvp.Value);
return cloneDictionary;
}
Wednesday, May 20, 2009
SharePoint Web-part dev problem - List does not exist
Problem:
I was working on a web-part with a custom ASPX file. It was working just fine for the root site of a site collection, but when testing it on a subsite it failed to load the ASPX file with the following exception:
List does not exist
The page you selected contains a list that does not exist. It may have been deleted by another user.
Solution:
There are few suggestions that didn't help me on the web. With the good old method - remove everything and check what's making the problem I found the perpetrator: in the ASPX page, I used SharePoint:FormattedStringWithListType, which caused the exception.
Using reflector I found that FormattedStringWithListType has a property 'List' which opens SPList with the current SPWeb context (list GUID is taken from the request parameter named 'List'). At this point I noticed that when the ASPX file is opened, it is done from the site collection level & not the sub site level.
From here there are few possible solutions:
*. Open the ASPX file from the subsite level (probably the best solution).
*. Don't use the class FormattedStringWithListType
*. Copy with reflector & fix the problem using SPSite.
I was working on a web-part with a custom ASPX file. It was working just fine for the root site of a site collection, but when testing it on a subsite it failed to load the ASPX file with the following exception:
List does not exist
The page you selected contains a list that does not exist. It may have been deleted by another user.
Solution:
There are few suggestions that didn't help me on the web. With the good old method - remove everything and check what's making the problem I found the perpetrator: in the ASPX page, I used SharePoint:FormattedStringWithListType, which caused the exception.
Using reflector I found that FormattedStringWithListType has a property 'List' which opens SPList with the current SPWeb context (list GUID is taken from the request parameter named 'List'). At this point I noticed that when the ASPX file is opened, it is done from the site collection level & not the sub site level.
From here there are few possible solutions:
*. Open the ASPX file from the subsite level (probably the best solution).
*. Don't use the class FormattedStringWithListType
*. Copy with reflector & fix the problem using SPSite.
Labels:
SharePoint
Saturday, March 28, 2009
Response.Header.Add doesn't work
I've tried to use:
Response.Header.Add("HeaderKeyName", "KeyValue")
But I got the following exception:
System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
at System.Web.HttpResponse.get_Headers()
The work around:
Response.AddHeader("HeaderKeyName", "KeyValue")
For the least Microsoft could find a better exception description.
Response.Header.Add("HeaderKeyName", "KeyValue")
But I got the following exception:
System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.
at System.Web.HttpResponse.get_Headers()
The work around:
Response.AddHeader("HeaderKeyName", "KeyValue")
For the least Microsoft could find a better exception description.
Labels:
ASP.NET
Tuesday, March 24, 2009
HyperLinkField not showing as link (ASP.NET)
After binding data to a HyperLinkField in a GridView it didn't show as link but as a normal text. Apparently when using navigation by data fields, the data in the fields set in DataNavigateUrlFields must be validated.
See some more information here:
http://stackoverflow.com/questions/640120/hyperlinkfield-not-showing-as-link
I had a problem when the field was a DateTime field returned by a database query. I've change the field format in the following way to make this work (navigation):
[Date] = convert(VARCHAR, [Date],104)
See some more information here:
http://stackoverflow.com/questions/640120/hyperlinkfield-not-showing-as-link
I had a problem when the field was a DateTime field returned by a database query. I've change the field format in the following way to make this work (navigation):
[Date] = convert(VARCHAR, [Date],104)
Labels:
ASP.NET,
GridView,
HyperLinkField
Tuesday, March 10, 2009
You are not authorized to view this page
Symptoms:
One clear morning, on an operational system (Windows 2003 x64, IIS, ASP.NET, SQL Server 2005) running an ASP.NET application, the users started to get request to fill their credentials, and after few times they got:
You are not authorized to view this page
With more specific notification:
HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials.Internet Information Services (IIS)
In the event log of the server I found the following errors:
- System Events - I found warning event 1011 titled "W3SVC":
A process serving application pool 'DefaultAppPool' suffered a fatal communication error with the World Wide Web Publishing Service. The process id was '6756'. The data field contains the error number.
A process serving application pool 'DefaultAppPool' suffered a fatal communication error with the World Wide Web Publishing Service. The process id was '6756'. The data field contains the error number.
- Application Events - I found error event 1000 titled ".NET Runtime 2.0 Error Reporting":
Faulting application w3wp.exe, version 6.0.3790.3959, stamp 45d691cc, faulting module kernel32.dll, version 5.2.3790.4062, stamp 462643a7, debug? 0, fault address 0x0000000000027d8d.
Faulting application w3wp.exe, version 6.0.3790.3959, stamp 45d691cc, faulting module kernel32.dll, version 5.2.3790.4062, stamp 462643a7, debug? 0, fault address 0x0000000000027d8d.
Resolution:
I followed few wrong leads on the web, such as:
- Permissions issue: http://support.microsoft.com/kb/918041/en-us
- SQL Server serface issue: http://www.sqlnewsgroups.net/group/microsoft.public.sqlserver.server/topic20191.aspx
After wasting nearly a day a found the root cause:
The ASP.NET application had a stack-overflow bug.
From here fixing is easy.
The reason that I didn't suspected the ASP.NET application was that the stack-overflow bug was caused by a run time change of the data in the application, and not something new installed/configured.
The ASP.NET application had a stack-overflow bug.
From here fixing is easy.
The reason that I didn't suspected the ASP.NET application was that the stack-overflow bug was caused by a run time change of the data in the application, and not something new installed/configured.
Subscribe to:
Posts (Atom)