Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for the ‘asp.net’ Category

Displaying Markers on the Chart via Microsoft Chart Controls

01 private void BindData() {
02
03 var exams = new List<Exam>()
04 {
05 new Exam() { Name = "Exam 1", Point = 10 },
06 new Exam() { Name = "Exam 2", Point = 12 },
07 new Exam() { Name = "Exam 3", Point = 15 },
08 new Exam() { Name = "Exam 4", Point = 2 }
09 };
10
11 var series = ExamsChart.Series["ExamSeries"];
12
13 foreach (var exam in exams) {
14
15 var point = new DataPoint();
16 point.SetValueXY(exam.Name, exam.Point);
17
18 point.Label = exam.Point.ToString();
19 series.Points.Add(point);
20 }
21
22 ExamsChart.DataSource = exams;
23 ExamsChart.DataBind();
24 }
Microsoft Chart

Microsoft Chart

FAQ in BlogEngine.NET

Can BlogEngine.NET be installed within an existing website?

Yes. Install it in its own folder and configure the directory it resides in as an application in IIS.

Some hosting providers may not allow the level of trust used in BlogEngine.NET by default. If you receive an error similar to:

  • “Parser Error Message: It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level.”,

You can try one of the following to resolve the issue:

  • Comment out the “trust” line in web.config
  • Ask your hosting provider if they can configure the directory where BlogEngine.NET is installed as a virtual directory.
  • Ask your hosting provider to verify that the directory has been configured as an application in IIS.

How do I update the “About the Author” section of the blog?

In the default Standard theme, edit the content of this section by clicking “edit” in on the side bar of your blog.

An alternative way to display About the Author information is to create a ‘Page’ in the control panel. The Title of the Page can be About the Author. Enter information about the author in the WYSIWYG editor. Once the page has been created, you can add a link to the About page on your blog. This can be achieved by adding a Page List widget, or by adding a TextBox widget with a hyperlink to the About page, or by editing your theme file (site.master) and adding a hyperlink to the About page.

Is BlogEngine.NET open source and completely free?

Yes. BlogEngine.NET is built by passionate developers who have too much spare time, just to make an open source blog engine to give away absolutely free.

Is my mother able to use it?

Yes. We have gone to great lengths to make BlogEngine.NET as easy as possible to use &ndash; both from an end user as well as a developer or theme designer’s point of view.

What are the demands for the web server?

The only thing needed to run BlogEngine.NET is a web server that support ASP.NET 2.0 and write permissions on the App_Data folder.

What database is it running on?

None. BlogEngine.NET uses XML to store all posts, pages etc. by default. However, if you prefer to use a database, BlogEngine.NET includes a “DbBlogProvider” that allows you to store data in databases which support standard SQL — MS SQL Server, MySql, SQLite and Vista DB among many others. Configuration changes necessary to store data in a SQL Server database can be found. If there isn’t a data provider already available, you can easily write your own provider. We have enginereed our framework to make this very easy and simple to do.

How can I switch where data is stored (XML to Database or vice versa)?

If you’re just starting off with BlogEngine.NET, all of your data will be stored in XML files in your App_Data folder. Some web hosts such as GoDaddy who have an automatic BlogEngine.NET setup option, might setup your blog so data is stored in a database instead. If your blog is new, you don’t yet have any data, and you want to switch from XML storage to Database storage

WebMatrix – Microsoft’s new web tool

What Is It?

WebMatrix is everything you need to build Web sites using Windows. It includes IIS Developer Express (a development Web server), ASP.NET (a Web framework), and SQL Server Compact (an embedded database). It streamlines Web site development and makes it easy to start Web sites from popular open-source apps. The skills and code you develop with WebMatrix transition seamlessly to Visual Studio and SQL Server.

Why Use It?

You will use the same powerful Web server, database engine and web framework that will run your Web site on the Internet, which makes the transition from development to product seamless. Beyond ensuring everything just works, WebMatrix includes new features that make Web development easier.

Who’s it for?

WebMatrix is for developers, students, or just about anyone who just wants a small and simple way to build Web sites. Start coding, testing, and deploying your own Web sites without having to worry about configuring your own Web server, managing databases, or learning a lot of concepts. WebMatrix makes Web site development easy.

Code Without Boundaries

WebMatrix provides an easy way to get started with Web development. With an integrated code editor and a database editor, Web site and server management, search optimization, FTP publishing, and more, WebMatrix provides a fresh, new Web site development experience that seamlessly bridges all the key components you need in order to create, run, and deploy a Web site.

Top Features:

Small, but complete package

WebMatrix is a free Web development tool that installs in minutes and elegantly brings together a Web server, a database, and programming frameworks into a single, integrated experience. WebMatrix lets you code, test, and deploy both ASP.NET and PHP applications side by side.

Grows with you

With WebMatrix on your desktop, you’re using the same powerful Web server, database engine, and frameworks that your Web site on the internet uses. This ensures that your transition from development to production is smooth and seamless.

When you’re ready, WebMatrix integrates Visual Studio into your workflow. Connect to Visual Studio to take advantage of powerful features such as debugging and profiling. And when you’re ready for a high-volume relational database server, move your database and data from SQL Server Compact to SQL Server with just a click of the mouse.

Start > Open Source

WebMatrix connects you to a world of popular and free open-source Web applications, including DotNetNuke, Umbraco, WordPress, Joomla!, and more. Simply select an application from the built-in gallery, and WebMatrix handles the downloading and installation of your new Web site. The days of hand-editing configuration files and making sure you have all the right components are long gone. Customize your site using the built in code editor and make it yours.

Database made simple

Using a database has never been easier! WebMatrix includes a small, embedded database called SQL Server Compact that can live with your Web site code and content. Use it to start building your next Web site, and when you’re ready to publish, just copy the database file from your computer to any Web server and it will run— no extra installation required. Or you can easily migrate the database and data to SQL Server when you’re ready for high-volume traffic.

Elegant interface, simple experience

WebMatrix integrates a rich code editor, a database editor, Web server management, Search Engine Optimization, FTP publishing, and more, WebMatrix provides a fresh, new, Web site development experience that bridges all the key components you need to create, run, and deploy a Web site.

Simple to code

WebMatrix is the easiest way to learn standards-based Web development and makes it simple to build and publish Web sites on the internet. Start with HTML, CSS and JavaScript and then seamlessly connect to a database or add in dynamic server code using the new ‘Razor’ syntax for ASP.NET Web pages. Your code is easy to read, simple to learn, short to write and works with any text editor. Use built-in helper functions to connect to a database, display a Twitter feed, or embed a video. And with a seamless path to ASP.NET MVC it is now easier than ever to create powerful ASP.NET Web applications.

More than “Hello, World”

Want to display a Twitter feed? Need to show a video? Code helpers make common tasks easy to do with just a simple tag in your HTML.

Desktop or server, it’s all the same

WebMatrix uses the same powerful Web server, database engine, and frameworks environment that will run your Web site on the Internet, which makes the transition from development to product seamless.

Tightly knit, fully integrated

WebMatrix integrates with IIS Developer Express and is tightly linked with the Web server components that run your site. Directly monitor real-time Web requests and responses to track down problems right at the source. Missing an image? You’ll instantly see why and where, and WebMatrix will take you directly to the file to fix the problem.

Optimize for search

Run an SEO report and find how to make your site more visible to search engines. WebMatrix takes the secrets out of search engine optimization, provides clear guidance on how to make your site better, and even offers to take you right to the file in your site you need to fix.

Site publishing

With WebMatrix you can find the perfect home for your Web site. Use WebMatrix to find a Web host that fits your requirements and use the built-in publishing support for FTP, FTPS, and WebDeploy to ensure that your files, databases, and settings arrive intact on the web.

Problems with an External (non-ASP.NET) Root Cause

Sometimes when you’re having trouble with an ASP.NET site, the problem turns out to not be ASP.NET itself. Here’s the top three issues and their causes. This category are for cases that were concluded because of external reasons and are outside of the control of support to directly affect. The sub categories are 3rd party software, Anti-virus software, Hardware, Virus attacks, DOS attacks, etc.

If you’ve ever run a production website you know there’s always that argument about whether to run anti-virus software in production. It’s not like anyone’s emailing viruses and saving them to production web servers, but you want to be careful. Sometimes IT or security insists on it. However, this means you’ll have software that is not your website software trying to access files at the same time your site is trying to access them.

Here’s the essence as a bulleted list

  • Concurrency while under pressure: This causes problems in big software. Make sure your anti-virus software is configure appropriately and that you’re aware of which processes are accessing which files, as well as how, why and when
  • Profile your applications: .NET and the Web are not black boxes. You can see what’s happening if you look. Know what bytes are going out the wire. Know who is accessing the disk. Measure twice, cut once, they say? I say measure a dozen times. You’d be surprised how often folks put an app in production and they’ve never once profiled it.
  • Anti-Virus Software: It can’t be emphasized enough that site owners should ensure they are running the latest AV engine and definitions from their chosen anti-malware vendor. They’ve see folks hitting hangs due to flakey AV drivers that are over two years out of date.  Another point about AV software is that it is not just about old-school AV scanning of file access. Many products now do low level monitoring of port activity, script activity within processes and memory allocation activity and do not always do these things 100% correctly. Stay up to date!
  • Know where you’re calling out to: Also, connection to remote endpoints: calling web services, accessing file systems etc. All of this can slow you down if you’re not paying attention. Is your DNS correct? Did you add your external hosts to a hosts file to remove DNS latency? 
  • processModel autoconfig=true: This is in machine.config and folks always mess with it. Don’t assume that you know better than the defaults. Everyone wants to change the defaults, add threads, remove threads, change the way the pool works because they think their textboxes-over-data application is special. Chances are it’s not, and you’d be surprised how often people will spend days on the phone with support and discover that the defaults were fine and they had changed them long ago and forgotten. Know what you’ve changed away from the defaults, and know why.

Building the Http Module with Logging Application Block

Building the Http Module

In order to build an Http module we only need to implement
the IHttpModule interface. The following is a simple
LoggingHttpModule which log details when a web request start
and when web request end:

using System;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
 
namespace HttpModules
{
  public class LoggingHttpModule : IHttpModule
  {
    #region Members
 
    private LogWriter _writer;
 
    #endregion
 
    #region IHttpModule Members
 
    public void Dispose()
    {
      if (_writer != null)
      {
        _writer.Dispose();
      }
    }
 
    public void Init(HttpApplication context)
    {
      CreateLogWriter();
      context.BeginRequest += new EventHandler(context_BeginRequest);
      context.EndRequest += new EventHandler(context_EndRequest);
    }
 
    private void CreateLogWriter()
    {
      ConfigureEnterpriseLibraryContainer();
      _writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
    }
 
    private void ConfigureEnterpriseLibraryContainer()
    {
      var builder = new ConfigurationSourceBuilder();
 
      builder.ConfigureInstrumentation().EnableLogging();
      builder.ConfigureLogging().WithOptions
             .LogToCategoryNamed("General")
               .WithOptions
               .SetAsDefaultCategory()
               .SendTo
               .FlatFile("Log File")
               .FormatWith(new FormatterBuilder()
               .TextFormatterNamed("Textformatter"))
                   .ToFile("file.log");
 
      var configSource = new DictionaryConfigurationSource();
      builder.UpdateConfigurationWithReplace(configSource);
      EnterpriseLibraryContainer.Current =
        EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
    }
 
    void context_BeginRequest(object sender, EventArgs e)
    {
      _writer.Write(new LogEntry
      {
        Message = "BeginRequest"
      });
    }
 
    void context_EndRequest(object sender, EventArgs e)
    {
      _writer.Write(new LogEntry
      {
        Message = "EndRequest"
      });
    }
 
    #endregion
  }
}

Using The Module

In order to use the module all we need to do is to add a reference
to the class library that holds the LoggingHttpModule. Then we need
to register the module in the web.config file in the httpModules 
element like:

<httpModules>
    <add name="LoggingHttpModlue" type="HttpModules.LoggingHttpModule, HttpModules"/>
</httpModules>

That is it. Now the module will be executed whenever a request
start or end.

ASP.NET MVC 2 RC2 (Release Candidate 2) Released

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).
The installation package includes templates and tools for Visual Studio 2008 SP 1 to increase productivity when writing ASP.NET MVC applications. For example, the Add View dialog box takes advantage of customizable code generation (T4) templates to generate a view based on a model object. The default project template allows the developer to automatically hook up a unit-test project that is associated with the ASP.NET MVC application.
Because the ASP.NET MVC framework is built on ASP.NET 3.5 SP 1, developers can take advantage of existing ASP.NET features like authentication and authorization, profile settings, localization, and so on. Download it at: http://www.microsoft.com/downloads/details.aspx?FamilyID=7aba081a-19b9-44c4-a247-3882c8f749e3&displaylang=en

What is new:

  • The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model properties are validated instead of just validations on changed values of a model).  This behavior change was based on extensive feedback from the community.
  • The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes.  This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML <input> element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.
  • The new templated Html.EditorFor() and Html.DisplayFor() helper methods now auto-scaffold simple properties (and do not render complex sub-properties by default).  This makes it easier to generate automatic scaffolded forms.  I’ll be covering this support in a future blog post.
  • The “id” attribute of client-script validation message elements is now cleaner.  With RC1 they had a form0_ prefix.  Now the id value is simply the input form element name postfixed with a validationMessage string (e.g. unitPrice_validationMessage).
  • The Html.ValidationSummary() helper method now takes an optional boolean parameter which enables you to control whether only model-level validation messages are rendered by it, or whether property level validation messages are rendered as well.  This provides you with more UI customization options for how validation messages are displayed within your UI.
  • The AccountController class created with the default ASP.NET MVC Web Application project template is cleaner.
  • Visual Studio now includes scaffolding support for Delete action methods within Controllers, as well as Delete views (I always found it odd that the default T4 templates didn’t support this before).
  • jQuery 1.4.1 is now included by default with new ASP.NET MVC 2 projects, along with a –vsdoc file that provides Visual Studio documentation intellisense for it.
  • The RC2 release has some significant performance tuning improvements (for example: the lambda based strongly-typed HTML helpers are now much faster).