MDSoft Weblog Mauro Destro software blog

This is my personal blog, here you find something about .NET, SCADA software I use and games in flash

09 Banner GIF

Best-sellers at Shop@US

maurodx aprile 1st, 2009

Tags: ,

Post correlati

Data Filtering with PHP

WebReference News luglio 4th, 2009

This article explores some of the new data filtering functions that became available in PHP 5.Nessun tag per questo post.

Post correlati

Check if Windows Server 2008

CodeKeep C# Feed luglio 2nd, 2009

Description: checks if the OS is Windows Server 2008

Link: http://www.codekeep.net/snippets/cd2d1f7d-25ef-4ef8-a86d-a8e41a43c74d.aspx

if (osVersion.Version.Major >= 6) //we have windows server 2008 or later

Nessun tag per questo post.

Post correlati

XML and PHP Simplified

WebReference News luglio 2nd, 2009

J. Leidago Noabeb simplifies and demystifies the use and application of XML and the DOM.

Nessun tag per questo post.

Post correlati

A Complete URL Rewriting Solution for ASP.NET 2.0

CodeKeep C# Feed luglio 1st, 2009

Description: A Complete URL Rewriting Solution for ASP.NET 2.0

Link: http://www.codekeep.net/snippets/40c55c2a-4766-4387-927f-650504651316.aspx

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.Xml;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.IO;
using System.Collections.Specialized;

namespace RewriteModule
{
    public class RewriteModuleSectionHandler : IConfigurationSectionHandler
    {

        private XmlNode _XmlSection;

        private string _RewriteBase;

        private bool _RewriteOn;

        public XmlNode XmlSection

        {

            get { return _XmlSection; }

        }

        public string RewriteBase

        {

            get { return _RewriteBase; }

        }

        public bool RewriteOn

        {

            get { return _RewriteOn; }

        }

        public object Create(object parent,object configContext, System.Xml.XmlNode section)
        {

            // set base path for rewriting module to

            // application root

            _RewriteBase = HttpContext.Current.Request.ApplicationPath + "/";

            // process configuration section

            // from web.config

            try

            {
                _XmlSection = section;
                _RewriteOn = Convert.ToBoolean(section.SelectSingleNode("rewriteOn").InnerText);

            }

            catch (Exception ex)

            {

                throw (new Exception("Error while processing RewriteModuleconfiguration section.", ex));

            }

            return this;

        }

    }

    /////////////////////

    ////////////////////

    class RewriteModule : IHttpModule
    {

        public void Dispose() { }

        public void Init(HttpApplication context)
        {
             //it is necessary to

            context.BeginRequest += new EventHandler(
                 RewriteModule_BeginRequest);
        }

        void RewriteModule_BeginRequest(object sender, EventArgs e)
        {

            RewriteModuleSectionHandler cfg =(RewriteModuleSectionHandler)ConfigurationManager.GetSection("modulesSection/rewriteModule");

            // module is turned off in web.config

            if (!cfg.RewriteOn) return;

            string path = HttpContext.Current.Request.Path;

            // there us nothing to process

            if (path.Length == 0) return;

            // load rewriting rules from web.config

            // and loop through rules collection until first match

            XmlNode rules = cfg.XmlSection.SelectSingleNode("rewriteRules");

            foreach (XmlNode xml in rules.SelectNodes("rule"))
            {

                try
                {

                    Regex re = new Regex(
                     cfg.RewriteBase + xml.Attributes["source"].InnerText,
                     RegexOptions.IgnoreCase);

                    Match match = re.Match(path);

                    if (match.Success)
                    {

                        path = re.Replace(
                             path,
                             xml.Attributes["destination"].InnerText);

                        if (path.Length != 0)
                        {

                            // check for QueryString parameters

                            if (HttpContext.Current.Request.QueryString.Count != 0)
                            {

                                // if there are Query String papameters

                                // then append them to current path

                                string sign = (path.IndexOf('?') == -1) ? "?" : "&";

                                path = path + sign +
                                   HttpContext.Current.Request.QueryString.ToString();

                            }

                            // new path to rewrite to

                            string rew = cfg.RewriteBase + path;

                            // save original path to HttpContext for further use

                            HttpContext.Current.Items.Add(

                              "OriginalUrl",

                              HttpContext.Current.Request.RawUrl);

                            // rewrite

                            HttpContext.Current.RewritePath(rew);

                        }

                        return;

                    }

                }

                catch (Exception ex)
                {

                    throw (new Exception("Incorrect rule.", ex));

                }

            }

            return;

        }

    }

}

//web.config

<configSections>
		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
				</sectionGroup>
			</sectionGroup>
		</sectionGroup>
		<sectionGroup name="modulesSection">
			<section name="rewriteModule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
		</sectionGroup>
	</configSections>

	<modulesSection>
		<rewriteModule>
			<rewriteOn>true</rewriteOn>
			<rewriteRules>
				<rule source="(\d+)/(\d+)/(\d+)/"  destination="Post.aspx?Year=$1&amp;Month=$2&amp;Day=$3"/>
				<rule source="(.*)/Default.aspx"  destination="Default.aspx?Folder=$1"/>
			</rewriteRules>
		</rewriteModule>
	</modulesSection>

use this link for detail
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/

Nessun tag per questo post.

Post correlati

enum

CodeKeep C# Feed giugno 30th, 2009

Description: enum

Link: http://www.codekeep.net/snippets/e08339fc-6eab-4f14-9698-576635881928.aspx

        public enum Filter
        {
            active = 0,
            archived = 1,
            all = 2
        }

Nessun tag per questo post.

Post correlati

Next »