Routing in ASP.NET 4

ASP.NET 4 adds built-in support for using routing with Web Forms. Routing lets you configure an application to accept request URLs that do not map to physical files. Instead, you can use routing to define URLs that are meaningful to users and that can help with search-engine optimization (SEO) for your application. For example, the URL for a page that displays product categories in an existing application might look like the following example:

http://website/products.aspx?categoryid=12

By using routing, you can configure the application to accept the following URL to render the same information:

http://website/products/software

Routing has been available starting with ASP.NET 3.5 SP1. However, ASP.NET 4 includes some features that make it easier to use routing, including the following:

· The PageRouteHandler class, which is a simple HTTP handler that you use when you define routes. The class passes data to the page that the request is routed to.

· The new properties HttpRequest.RequestContext and Page.RouteData (which is a proxy for the HttpRequest.RequestContext.RouteData object). These properties make it easier to access information that is passed from the route.

· The following new expression builders, which are defined in System.Web.Compilation.RouteUrlExpressionBuilder and System.Web.Compilation.RouteValueExpressionBuilder:

· RouteUrl, which provides a simple way to create a URL that corresponds to a route URL format within an ASP.NET server control.

· RouteValue, which provides a simple way to extract information from the RouteContext object.

· The RouteParameter class, which makes it easier to pass data contained in a RouteContext object to a query for a data source control (similar to FormParameter).

Routing for Web Forms Pages

The following example shows how to define a Web Forms route by using the new MapPageRoute method of the Route class:

public class Global : System.Web.HttpApplication

{

void Application_Start(object sender, EventArgs e)

{

RouteTable.Routes.MapPageRoute("SearchRoute",

"search/{searchterm}", "~/search.aspx");

RouteTable.Routes.MapPageRoute("UserRoute",

"users/{username}", "~/users.aspx");

}

}

ASP.NET 4 Beta 2 introduces the MapPageRoute method. The following example is equivalent to the SearchRoute definition shown in the previous example, but uses the PageRouteHandler class.

RouteTable.Routes.Add("SearchRoute", new Route("search/{searchterm}",

new PageRouteHandler("~/search.aspx")));

The code in the example maps the route to a physical page (in the first route, to ~/search.aspx). The first route definition also specifies that the parameter named searchterm should be extracted from the URL and passed to the page.

The MapPageRoute method supports the following method overloads:

· MapPageRoute(string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess)

· MapPageRoute(string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, RouteValueDictionary defaults)

· MapPageRoute(string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, RouteValueDictionary defaults, RouteValueDictionary constraints)

The checkPhysicalUrlAccess parameter specifies whether the route should check the security permissions for the physical page being routed to (in this case, search.aspx) and the permissions on the incoming URL (in this case, search/{searchterm}). If the value of checkPhysicalUrlAccess is false, only the permissions of the incoming URL will be checked. These permissions are defined in the Web.config file with settings such as the following:

<configuration>

<location path="search.aspx">

<system.web>

<authorization>

<allow roles="admin"/>

<deny users="*"/>

</authorization>

</system.web>

</location>

<location path="search">

<system.web>

<authorization>

<allow users="*"/>

</authorization>

</system.web>

</location>

</configuration>

In the example configuration, access is denied to the physical page search.aspx for all users except those who are in the admin role. When the checkPhysicalUrlAccess parameter is set to true (which is its default value), only admin users are allowed to access the URL /search/{searchterm}, because the physical page search.aspx is restricted to users in that role. If checkPhysicalUrlAccess is set to false and the site is configured as shown in the previous example, all authenticated users are allowed to access the URL /search/{searchterm}.

Posted in: asp.net | Tags: xml asp.net asp.net 4.0 eventargs routing pageroutehandler httprequest requestcontext routevalueexpressionbuilder web form page authorization location configuration

55 screening questions for Windows admin

  1. What is Active Directory?
  2. What is LDAP?
  3. Can you connect Active Directory to other 3rd-party Directory Services? Name a few options.
  4. Where is the AD database held? What other folders are related to AD?
  5. What is the SYSVOL folder?
  6. Name the AD NCs and replication issues for each NC
  7. What are application partitions? When do I use them
  8. How do you create a new application partition
  9. How do you view replication properties for AD partitions and DCs?
  10. What is the Global Catalog?
  11. How do you view all the GCs in the forest?
  12. Why not make all DCs in a large forest as GCs?
  13. Trying to look at the Schema, how can I do that?
  14. What are the Support Tools? Why do I need them?
  15. What is LDP? What is REPLMON? What is ADSIEDIT? What is NETDOM? What is REPADMIN?
  16. What are sites? What are they used for?
  17. What’s the difference between a site link’s schedule and interval?
  18. What is the KCC?
  19. What is the ISTG? Who has that role by default?
  20. What are the requirements for installing AD on a new server?
  21. What can you do to promote a server to DC if you’re in a remote location with slow WAN link?
  22. How can you forcibly remove AD from a server, and what do you do later? • Can I get user passwords from the AD database?
  23. What tool would I use to try to grab security related packets from the wire?
  24. Name some OU design considerations.
  25. What is tombstone lifetime attribute?
  26. What do you do to install a new Windows 2003 DC in a Windows 2000 AD?
  27. What do you do to install a new Windows 2003 R2 DC in a Windows 2003 AD?
  28. How would you find all users that have not logged on since last month?
  29. What are the DS* commands?
  30. What’s the difference between LDIFDE and CSVDE? Usage considerations?
  31. What are the FSMO roles? Who has them by default? What happens when each one fails?
  32. What FSMO placement considerations do you know of?
  33. I want to look at the RID allocation table for a DC. What do I do?
  34. What’s the difference between transferring a FSMO role and seizing one? Which one should you NOT seize? Why?
  35. How do you configure a “stand-by operation master” for any of the roles?
  36. How do you backup AD?
  37. How do you restore AD?
  38. How do you change the DS Restore admin password?
  39. Why can’t you restore a DC that was backed up 4 months ago?
  40. What are GPOs?
  41. What is the order in which GPOs are applied?
  42. Name a few benefits of using GPMC.
  43. What are the GPC and the GPT? Where can I find them?
  44. What are GPO links? What special things can I do to them?
  45. What can I do to prevent inheritance from above?
  46. How can I override blocking of inheritance?
  47. How can you determine what GPO was and was not applied for a user? Name a few ways to do that.
  48. A user claims he did not receive a GPO, yet his user and computer accounts are in the right OU, and everyone else there gets the GPO. What will you look for?
  49. Name a few differences in Vista GPOs
  50. Name some GPO settings in the computer and user parts.
  51. What are administrative templates?
  52. What’s the difference between software publishing and assigning?
  53. Can I deploy non-MSI software with GPO?
  54. You want to standardize the desktop environments (wallpaper, My Documents, Start menu, printers etc.) on the computers in one department. How would you do that?
  55. What do you do to install a new Windows 2003 DC in a Windows 2000 AD?
Posted in: Interview Questions | Tags: windows config configuration windows admin admin sys partion ad microsoft ad active directory kcc ldp gc gcs windows 2003 windows 2008 server rid dc ds life time

Logging with Spring in .NET

Introduction

To avoid introducing a dependency on a particular logging framework Spring uses it's own logging abstraction: the "Common.Logging" library. This library is based on work done by the developers of IBatis.NET and it's usage is inspired by log4net. It provides an easy mechanism to plug in any logging framework using FactoryAdapters.

Configuring Logging

Declarative Configuration

Logging configuration can be done declaratively in your app.config:

<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
<arg key="showDateTime" value="true" />
</factoryAdapter>
</logging>
</common>
</configuration>

The concrete set of <arg> elements you may specify depend on the FactoryAdapter being used.

Configuring Logging in your code

You may manually configure logging by setting a LoggerFactoryAdapter in your code:

// create properties
NameValueCollection properties = new NameValueCollection();
properties["showDateTime"] = "true";
// set Adapter
Common.Logging.LogManager.Adapter =
new Common.Logging.Simple.TraceLoggerFactoryAdapter(properties);

The concrete set of properties you may specify depend on the FactoryAdapter being used.

Using Common.Logging API in your own code

Usage of the Logging API is fairly simple. You need to obtain a logger from the LogManager and call the appropriate logging method:

using Common.Logging;
...
ILog log = LogManager.GetLogger(this.GetType());
log.Debug("hello world");

It is also possible to obtain a logger by name:

ILog log = LogManager.GetLogger("mylogger");

The methods available for logging are:

  • Debug()
  • Info()
  • Warn()
  • Error()
  • Fatal()

All methods are overloaded to support logging exceptions as well.

Since ILog interface mimics the look&feel of log4net, migration is just a matter of changing the "using" statement.

Posted in: programming asp.net | Tags: .net c# asp.net configuration logging spring configuring logging configsections sectiongroup configurationsectionhandler factoryadapter