ASP.NET

ASP.NET

Change DocType dynamically

I have a single page(created before Master pages were available) that loaded dynamically one or another user control.Some child controls have css for quirk mode, but for new controls I want to use latest DocType <!DOCTYPE html> The solution is to set it dynamically in code-behind depending on current control to load(the code is copied from http://stackoverflow.com/qu... =========aspx=============== <%@ Page Language="C#"...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Changing “Trusted Sites” list affected HttpWebRequest in application running under different account

We have a webscraper ASP.Net application, that worked fine on developers and test environments, but didn’t work on some machines with more strict security settings. HttpWebRequest failed with System.Net.WebException: Unable to connect to the remote server It start working when my colleague added the site that application tried to access to his “Trusted Sites” zone using Internet Explorer. What we couldn’t understand, how it affected an application that ran under DIFFERENT account. I didn’t find any...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Localization Approach for ASP.NET Web site

String Resources For string resources we will use local/global resources connecting to DB using DbResourceProvider from “Creating a Data Driven ASP.NET Localization Resource Provider and Editor” http://www.west-wind.com/pr... It also has DbResourceControl, that shows controls with Localizable attribute and connect them to editor. From http://guysmithferrier.com/... and http://www.guysmithferrier....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Combining javascript files

I’ve read Combining Client Scripts into a Composite Script and wanted to use it. Then I’ve read Julian Jelfs concerns ScriptManager.CompositeScript issues However the article Combining javascript files with Ajax toolkit library describes workarounds, that make the solution workable. You also can use Script reference profiler: http://aspnet.codeplex.com/... Related posts: Using ScriptManager with other frameworks MSDN documentation: CompositeScriptReference The older implementations,...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Message : A potentially dangerous Request.Path value was detected from the client (:).

We’ve noticed in event log the following error: Message : A potentially dangerous Request.Path value was detected from the client (:). Type : System.Web.HttpException, System.Web, Version=4.0.0.0, Culture=neutral, Message : A potentially dangerous Request.Path value was detected from the client (:). Source : System.Web WebEventCode : 0 ErrorCode : -2147467259 Stack Trace : at System.Web.HttpRequest.Vali... at System.Web.HttpApplication....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Validation of Html file

We’ve used HtmlAgilityPack based function IsValidHtmlFragment(string html) to validate dynamically loaded Html Fragments before inserting into main page(or do not insert if it is invalid) and recently noticed that it doesn’t return false for some fragments with not closed tags. I decided to find some other tool to call from the code and found that most of HTML parcers are too forgivven(like browsers) or too strict- to check full XHTML conformance. I am going to add manual procedure to run Tidy.EXE...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

RemoveQueryStringFromUrl helper function

I've recently added to my UriHelper class the function RemoveQueryStringFromUrl public static string RemoveQueryStringFromUrl(st... url) { //similar to string qs = QueryStringHelper.QueryStri... string urlPath = url.LeftBefore("?"); return urlPath; } It refers to methods from My QueryStringHelper class and My StringHelper class...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Remix10 AU- lessons learned.

I've attended Australian Remix10 and below is a list the points, that I've learned and/or want to read more about. The materials of US MIX10 conference are here http://live.visitmix.com/ Windows Azure ( pronounced [azh-er] http://dictionary.reference... - sounds great from hosting costs/redundancy, but how much work is required to change existing asp.net application with SQL backend to support Azure. http://www.azuresupport.com...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Upgrade to ASP.Net 4 on Web Farm

Recently we upgraded Web Farm web site to ASP.Net 4. We studied .NET Framework 4 Migration Issues and, fortunately, didn't found any serious issues, related to our site. Before all sites will be converted to .Net 4, for forms authentication cookies to work across .NET Framework versions, we've added <system.web> <machineKey validation="SHA1" /> </system.web> Tests were successfull on single computer, but when we started to test new version on Web Farm, we started to see intermittent...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Helper methods StartOfMonth and StartOfNextMonth

There are couple methods recently added to My DateTimeHelper class public static DateTime StartOfMonth(this DateTime dateValue) { return new DateTime(dateValue.Year,dat... } public static DateTime StartOfNextMonth(this DateTime dateValue) { return StartOfMonth(dateValue).Add... }...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

My version of UnhandledExceptionModule

I've created my own version of UnhandledExceptionModule independantly of codePlex project in 2007, I've used code from http://support.microsoft.co... with considerations from http://www.eggheadcafe.com/... and done some refactoring. It also allows to use AppSettings["EventLogSource... The zip file also includes TestUnhandledExceptionWAP test project, that I used to investigate issue legacyUnhandledExceptionPolicy enabled="true" doesn't prevent ASP.NET application restarting...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

DDD Melbourne -lessons learned

I've attended DDD Melbourne and want to list the interesting points, that I've learned and want to follow. To read more: * Moles-Mocking Isolation framework for .NET. Documentation is here. (See also Mocking frameworks comparison created October 4, 2009 ) * WebFormsMVP * PluralSight http://www.pluralsight-trai... * ELMAH: Error Logging Modules and Handlers Great for new sites or sites without error logging/monitoring. However if you site already have working error...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

JavaScript function to Redirect parent of IFrame to specified URL

/// <summary> /// Redirects parent of IFrame to specified URL /// If current page doesn't have parent, redirect itself /// </summary> /// <param name="page"></param> /// <param name="url"></param> public static void NavigateParentToUrl(Page page, string url) { String script = @" try { var sUrl='" + url + @"'; if (self.parent.frames.length != 0) self.parent.location=sUrl; else self.location = sUrl; } catch (Exception) {} "; page.ClientScript.RegisterS...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comment in JavaScript code doesn't comment the server command

Comment in JS code doesn't comment the server command. It is correct, but can be visually confusing. I had the following line in markup ASCX file. // var trs = document.getElementById('&l... %>').getElementsByTagNam... Visual Studio showed it as green comment. However when server control pnlOutsideSearch was renamed, the errors were generated, and it took me some time to realize, what wrong with the line, tha it was look like just comment...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

ASP.NET Validators should be visible to do validation

Validators are disabled, if they are not visible. They can be not visible, if any of their containers is not visible. In general, they should be always visible, but the message will be shown only if they will be NOT valid. Also consider to set BaseValidator.SetFocusOnErr... In big pages use ValidationGroup combined with CausesValidation property set to true...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

ASP.NET Conversion to WAP bug - autoeventwireup Changed to True

When ASP.NET page converted to WAP, it changed autoeventwireup to True- see autoeventwireup Changed to True in C# Conversion to WAP discussion. Autoeventwireup is easier for coding, but there are disadvantages(according to MSDN): One disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name event handlers. Another disadvantage is that performance is adversely affected, because ASP.NET...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Insert CSS link with updatable version number in URL

More than a year ago I wrote a post Code Render Blocks does not work inside HEAD server controls about the problem, that prevented me to update URL of CSS file, when version of assembly incremented. Now I've created a function /// <summary> /// /// </summary> /// <param name="page"></param> /// <param name="cssFileHref">e.g. "~/StyleSheet.css"</para... /// <returns></returns... public static HtmlLink AddStyleSheetLink(this Page page, string cssFileHref)...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Display content of page in a modal dialog- consider jqModal.

I need to show popup info message with single close button, but content is located in separate html file. The current implementation using window.open not working for many users with popup blockers. My question is which tool/framework should I use. Initially I considered to use UFrame (see CodeProject article:UFrame: goodness of UpdatePanel and IFRAME combined )inside ASP.NET AJAX ModalPopup. Then I found question http://stackoverflow.com/qu...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Specify Expect100Continue=false in Web Service client.

The Web Service Provider that we are using recommends NOT send Expect100Continue header. The specifying static value System.Net.ServicePointMana... is not good, because some other providers may prefer to use the header. In the haacked's "HttpWebRequest and the Expect: 100-continue Header Problem" post comment of Mirronelli Jun 02, 2005 6:22 AM suggest to specify webRequest.ServicePoint.Exp... = false; for each webRequest. If I am using web service(derived from...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

IIS Set Expiration Dates adds the expiration header only to static content

12 Steps To Faster Web Pages With Visual Round Trip Analyzer recommends (among others useful suggestions) to Set Expiration Dates - follow Using Content Expiration (IIS 6.0), . I've looked in a few articles, including Best Practices for Speeding Up Your Web Site, "Optimizing a Page-Load Performance Profile and Optimization of a Web Site - Using Content Expiration (IIS 6.0) . Finally the post IIS Content expiration header and ASP.NET cleared my concerns: IIS is smart enough to add the expiration header...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Full ASP.NET Archive

«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910