SlideShare ist ein Scribd-Unternehmen logo
1 von 50
1
Daniel Fisher
daniel.fisher@devcoach.biz
2
Daniel Fisher CTO.
MCP, MCTS, MCPD…
Mit-Gründer und Geschäftsführer von
devcoach®
Mit-Gründer und Vorstand der
just community e.V.
Leiter der .NET-Nieder-Rhein
INETA User-Group
Mitglied im Microsoft
Community Leader & Insider Program (CLIP)
Connected Systems Advisory Board
3
Projekte, Beratung & Training
 REST & SOA – Architektur
 BPM & FDD – Prozesse
 Sicherheit & Claims – Identity
 DAL & ORM – Daten
 RIA & AJAX – Web 2.0
Technologien
 ASP.NET, WCF, WF & CardSpace – .NET
Kunden
 Versicherungen, Großhandel, Software – u.A. Microsoft
Project
Experience
Technology
Know-how
devcoach®
4
 Nice URLs
 URL Rewriting
 IIS Rewriting Module
 Classic ASP.NET
 ASP.NET Routing Engine
 Solving Postback Issues
5
6
http://www.basta.net/View.aspx?y={7B5BBD55-
40F3-4ccb-852D-E6D0DB3D308D}&
t={31646FBE-CC9C-43c8-AB77-
BE149F2C2B99}&c={070877AA-668D-47d7-
872E-5838CD5E2F8B}
daniel.fisher@devcoach.biz
7
http://www.basta.net/2009/Speakers
daniel.fisher@devcoach.biz
8
 Usability-Guru Jakob Neilsen recommends that
URLs be chosen so that they:
 Are short.
 Are easy to type.
 Visualize the site structure.
 "Hackable," allowing the user to navigate through
the site by hacking off parts of the URL.
daniel.fisher@devcoach.biz
9
 Dynamic web pages like ASP.NET rely on
parameters as non web apps do.
 Web applications user GET or POST variables
to transmit values.
 Query strings are
 Not soooooo nice
 Hard to remember
 Look like parameters
 Internally they are but for instance looking at a categories
products is not seen as an action by the user…
daniel.fisher@devcoach.biz
10daniel.fisher@devcoach.biz
11
Operating System
HTTP.SYS
Internet Information Services
InetInfo
•Metabase
W3SVC
•ProcMgr
•ConfMgr
Application Pool – W3WP.exe
WebApp
•Global
•Modules
•Handler
WebApp
•Global
•Modules
•Handler
Cache
12
HTTP.SYS IIS aspnet_isa
pi.dll
Module HandlerModuleModuleModule
13
HTTP.SYS IIS Module HandlerModuleModuleModule
14daniel.fisher@devcoach.biz
15
 Rule based
 UI (IISMGR)
 ISAPI extension
 Global and distributed rewrite rules
 …
 It's Infrastructure!
16
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^default.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
<add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="default.aspx?{R:1}={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
17
Creating a "nice" URL
18
 IIS URL Rewrite Module updates ASP.NET bugs
 "~" is resolved incorrectly when using URL rewriting
 SiteMap.CurrentNode property returns null when sitemap
contains virtual URLs
 Only if the machine has .NET Framework version 3.5
SP1 or higher.
 If .NET is installed after URL Rewrite re-install or
repair!
19
 IIS URL Rewrite Module
 x86:
http://www.microsoft.com/downloads/details.aspx?
FamilyID=836778ea-b2f2-4907-b2dc-
a152ec0a4bc4&displaylang=en
 x64:
http://www.microsoft.com/downloads/details.aspx?f
amilyid=6C15B777-8D9E-4D99-B359-
A98E2C0880F7&displaylang=en
20daniel.fisher@devcoach.biz
21
 HTTP Handler
 HTTP Module
22
public class MyRewriterModule : IHttpModule
{
public virtual void Init(HttpApplication app)
{
app.AuthorizeRequest += RewriteRequest;
}
protected void RewriteRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
HttpContext.Current.RewritePath("My.aspx?id=42");
}
...
}
23
<configuration>
<system.web>
<httpModules>
<add
type="MyRewriterModule, App_Code"
name="ModuleRewriter" />
</httpModules>
<!–- or -->
<httpHandlers>
<add
verb="*"
path="*.aspx"
type="MyRewriterFactoryHandler, App_Code" />
</httpHandlers>
</system.web>
</configuration>
24
Utilizing HttpContext.RewritePath()
Method
25
26
 Code your own matching logic 
 Code your own rule provider 
 Code your own replace mechanizm 
27
 IIS 7 is configured to not authenticate
content that is not handled internally
 A virtual URL points to an non-existent file
 You need to enable URL Authentication on rewriten
requests
 A) Change preCondition of UrlAuthenticationModule
 B) Call Authentication yourself
28
29
 A gerneric module to redirect calls to URLs to
ASP.NET Page endpoints.
 Namespace: System.Web.Routing
 Built for the ASP.NET MVC Framework
30
RouteTable is created
UrlRoutingModule intercepts the request
MvcHandler executes
Controller executes
RenderView method is executed
31
 Each URL Rewrite is defined as entry of the
RouteTable.
 In MVC the Route Table maps URLs to controllers.
 It is setup in the Global.asax
32
<configuration>
…
<system.web>
…
<httpModules>
…
<add
name="urlRouting"
type="System.Web.Routing.UrlRoutingModule"/>
</httpModules>
…
33
<%@ Application Language="C#" %>
<script runat="server">
static void RegisterRoutes()
{
RouteTable.Routes.Add(
new Route(
"articles",
new MyRoutingPageHandler()));
}
…
34
public class RoutingPageHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var pathData =
requestContext.RouteData.Route.GetVirtualPath(
requestContext,
requestContext.RouteData.Values);
return pathData.VirtualPath.Contains("articles")
? (IHttpHandler)BuildManager.
CreateInstanceFromVirtualPath(
"~/Default.aspx", typeof(Page))
: (IHttpHandler)BuildManager.
CreateInstanceFromVirtualPath(
"~/Default2.aspx", typeof(Page));
}
…
35
Create and handle routes
NOTE: Don't forget to add the required
extension if you're trying this with IIS 6…
36
37
RouteTable.Routes.Add(
new Route(
"articles/{id}",
new MyRoutingPageHandler()));
38
var queryString = new StringBuilder("?");
var serverUtil = httpContext.Server;
// Copy route data...
foreach (var aux in requestContext.RouteData.Values)
{
queryString.Append(serverUtil.UrlEncode(aux.Key));
queryString.Append("=");
queryString.Append(
serverUtil.UrlEncode(aux.Value.ToString()));
queryString.Append("&");
}
39
40
requestContext.HttpContext.RewritePath(
string.Concat(
virtualPath,
queryString));
(IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(
virtualPath,
typeof(Page));
41
 ASP.NET has no clue that a request is
"routed" and authenticates the
requested URL – the virtual path 
42
var modules = e.HttpContext.ApplicationInstance.Modules;
if (modules["UrlAuthorization"] != null &&
UrlAuthorizationModule.CheckUrlAccessForPrincipal(
e.VirtualPath,
e.HttpContext.User,
e.HttpContext.Request.HttpMethod))
{
return;
}
if (e.HttpContext.GetAuthenticationMode() !=
AuthenticationMode.Forms)
{
return;
}
e.VirtualPath = FormsAuthentication.LoginUrl;
e.QueryString =
string.Concat(
"?ReturnUrl=",
e.HttpContext.Server.UrlEncode(
e.HttpContext.Request.RawUrl));
43
Parameters, QueryStrings and
FormsAuthentication
NOTE: Don't forget to add the required
extension if you're trying this with IIS 6…
44
45daniel.fisher@devcoach.biz
46
public class Form : HtmlForm
{
protected override void RenderAttributes(HtmlTextWriter writer)
{
writer.WriteAttribute("name", Name);
Attributes.Remove("name");
writer.WriteAttribute("method", Method);
Attributes.Remove("method");
Attributes.Render(writer);
Attributes.Remove("action");
if (!string.IsNullOrEmpty(ID))
{
writer.WriteAttribute("id", ClientID);
}
}
}
47
_context.Response.Filter = new ResponseFilter(_context.Response.Filter);
...
public override void Write(byte[] buffer, int offset, int count)
{
if (HttpContext.Current.Items["VirtualPath"] != null)
{
var str = Encoding.UTF8.GetString(buffer);
var path = HttpContext.Current.Request.Url.PathAndQuery;
str = str.Replace(
string.Concat(
"="",
path.Substring(path.LastIndexOf("/") + 1),
"""),
string.Concat(
"="",
(string)HttpContext.Current.Items["VirtualPath"],
"""));
buffer = Encoding.UTF8.GetBytes(str);
}
_sink.Write(buffer, offset, count);
}
48
49
 URL rewriting is used to
manipulate URL paths
before the request is
handled by the Web
server.
 The URL-rewriting module
does not know anything
about what handler will
eventually process the
rewritten URL.
 In addition, the actual
request handler might not
know that the URL has
been rewritten.
 ASP.NET routing is used
to dispatch a request to a
handler based on the
requested URL path.
 As opposed to URL
rewriting, the routing
component knows about
handlers and selects the
handler that should
generate a response for
the requested URL.
 You can think of ASP.NET
routing as an advanced
handler-mapping
mechanism.
50
The presentation content is provided for your personal information only. Any commercial or non-commercial use of the presentation in full or of any text or graphics
requires a license from copyright owner. This presentation is protected by the German Copyright Act, EU copyright regulations and international treaties.

Weitere ähnliche Inhalte

Andere mochten auch

Azure App Service at Let's Dev This
Azure App Service at Let's Dev ThisAzure App Service at Let's Dev This
Azure App Service at Let's Dev ThisGuy Barrette
 
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...Maarten Balliauw
 
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your Organization
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your OrganizationEPIP - Ask For It - Webinar: Negotiating for Yourself and Your Organization
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your OrganizationEPIPNational
 
2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineeringDaniel Fisher
 
Azure App Service Architecture. Web Apps.
Azure App Service Architecture. Web Apps.Azure App Service Architecture. Web Apps.
Azure App Service Architecture. Web Apps.Alexander Feschenko
 
Microsoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure PlatformMicrosoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure PlatformDavid Chou
 

Andere mochten auch (8)

Azure App Service at Let's Dev This
Azure App Service at Let's Dev ThisAzure App Service at Let's Dev This
Azure App Service at Let's Dev This
 
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...Windows Azure Web Sites- Things they don’t teach kids in school - Comunity D...
Windows Azure Web Sites - Things they don’t teach kids in school - Comunity D...
 
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your Organization
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your OrganizationEPIP - Ask For It - Webinar: Negotiating for Yourself and Your Organization
EPIP - Ask For It - Webinar: Negotiating for Yourself and Your Organization
 
2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering2009 - Basta!: Agiles requirements engineering
2009 - Basta!: Agiles requirements engineering
 
Azure App Service Architecture. Web Apps.
Azure App Service Architecture. Web Apps.Azure App Service Architecture. Web Apps.
Azure App Service Architecture. Web Apps.
 
Azure Cloud PPT
Azure Cloud PPTAzure Cloud PPT
Azure Cloud PPT
 
Microsoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure PlatformMicrosoft Cloud Computing - Windows Azure Platform
Microsoft Cloud Computing - Windows Azure Platform
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Ähnlich wie 2009 - Basta!: Url rewriting mit iis, asp.net und routing engine

Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauSpiffy
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVCDaniel Fisher
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutionswoutervugt
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019Matt Raible
 
Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvcmicham
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsShahed Chowdhuri
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworksEric Guo
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetesBen Hall
 
Staying Ahead of the Curve with Spring and Cassandra 4
Staying Ahead of the Curve with Spring and Cassandra 4Staying Ahead of the Curve with Spring and Cassandra 4
Staying Ahead of the Curve with Spring and Cassandra 4VMware Tanzu
 
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)Alexandre Dutra
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsShahed Chowdhuri
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET DeveloperJohn Calvert
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop OverviewShubhra Kar
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices -  Michael HacksteinNoSQL meets Microservices -  Michael Hackstein
NoSQL meets Microservices - Michael Hacksteindistributed matters
 
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...MUG-Lyon Microsoft User Group
 
Playing with php_on_azure
Playing with php_on_azurePlaying with php_on_azure
Playing with php_on_azureCEDRIC DERUE
 

Ähnlich wie 2009 - Basta!: Url rewriting mit iis, asp.net und routing engine (20)

Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC2010 - Basta!: REST mit ASP.NET MVC
2010 - Basta!: REST mit ASP.NET MVC
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutions
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
 
Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworks
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 
Staying Ahead of the Curve with Spring and Cassandra 4
Staying Ahead of the Curve with Spring and Cassandra 4Staying Ahead of the Curve with Spring and Cassandra 4
Staying Ahead of the Curve with Spring and Cassandra 4
 
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)
Staying Ahead of the Curve with Spring and Cassandra 4 (SpringOne 2020)
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET Developer
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices -  Michael HacksteinNoSQL meets Microservices -  Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
 
Playing with php_on_azure
Playing with php_on_azurePlaying with php_on_azure
Playing with php_on_azure
 
Asp.net
Asp.netAsp.net
Asp.net
 

Mehr von Daniel Fisher

MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityDaniel Fisher
 
NRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityNRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityDaniel Fisher
 
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an....NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...Daniel Fisher
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und buildDaniel Fisher
 
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...Daniel Fisher
 
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...Daniel Fisher
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGETDaniel Fisher
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST WarsDaniel Fisher
 
2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC LocalizationDaniel Fisher
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5Daniel Fisher
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAXDaniel Fisher
 
2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#Daniel Fisher
 
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVCDaniel Fisher
 
2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCF2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCFDaniel Fisher
 
2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET Membership2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET MembershipDaniel Fisher
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#Daniel Fisher
 
2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als CacheDaniel Fisher
 
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrowDaniel Fisher
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with VoltaDaniel Fisher
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageabilityDaniel Fisher
 

Mehr von Daniel Fisher (20)

MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
 
NRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragilityNRWConf, DE: Defensive programming, resilience patterns & antifragility
NRWConf, DE: Defensive programming, resilience patterns & antifragility
 
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an....NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
.NET Developer Days 2015, PL: Defensive programming, resilience patterns & an...
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
 
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
2015 - Basta! 2015, DE: Defensive programming, resilience patterns & antifrag...
 
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
2015 - Network 2015, UA: Defensive programming, resilience patterns & antifra...
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET
 
2011 - DNC: REST Wars
2011 - DNC: REST Wars2011 - DNC: REST Wars
2011 - DNC: REST Wars
 
2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization2011 - DotNetFranken: ASP.NET MVC Localization
2011 - DotNetFranken: ASP.NET MVC Localization
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
 
2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#2010 - Basta!: IPhone Apps mit C#
2010 - Basta!: IPhone Apps mit C#
 
2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC2010 - Basta: ASP.NET Controls für Web Forms und MVC
2010 - Basta: ASP.NET Controls für Web Forms und MVC
 
2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCF2009 - Microsoft Springbreak: IIS, PHP & WCF
2009 - Microsoft Springbreak: IIS, PHP & WCF
 
2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET Membership2009 - NRW Conf: (ASP).NET Membership
2009 - NRW Conf: (ASP).NET Membership
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
 
2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache2009 - DNC: Silverlight ohne UI - Nur als Cache
2009 - DNC: Silverlight ohne UI - Nur als Cache
 
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
2008 - TechDays PT: Modeling and Composition for Software today and tomorrow
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 

Kürzlich hochgeladen

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Kürzlich hochgeladen (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

2009 - Basta!: Url rewriting mit iis, asp.net und routing engine

  • 2. 2 Daniel Fisher CTO. MCP, MCTS, MCPD… Mit-Gründer und Geschäftsführer von devcoach® Mit-Gründer und Vorstand der just community e.V. Leiter der .NET-Nieder-Rhein INETA User-Group Mitglied im Microsoft Community Leader & Insider Program (CLIP) Connected Systems Advisory Board
  • 3. 3 Projekte, Beratung & Training  REST & SOA – Architektur  BPM & FDD – Prozesse  Sicherheit & Claims – Identity  DAL & ORM – Daten  RIA & AJAX – Web 2.0 Technologien  ASP.NET, WCF, WF & CardSpace – .NET Kunden  Versicherungen, Großhandel, Software – u.A. Microsoft Project Experience Technology Know-how devcoach®
  • 4. 4  Nice URLs  URL Rewriting  IIS Rewriting Module  Classic ASP.NET  ASP.NET Routing Engine  Solving Postback Issues
  • 5. 5
  • 8. 8  Usability-Guru Jakob Neilsen recommends that URLs be chosen so that they:  Are short.  Are easy to type.  Visualize the site structure.  "Hackable," allowing the user to navigate through the site by hacking off parts of the URL. daniel.fisher@devcoach.biz
  • 9. 9  Dynamic web pages like ASP.NET rely on parameters as non web apps do.  Web applications user GET or POST variables to transmit values.  Query strings are  Not soooooo nice  Hard to remember  Look like parameters  Internally they are but for instance looking at a categories products is not seen as an action by the user… daniel.fisher@devcoach.biz
  • 11. 11 Operating System HTTP.SYS Internet Information Services InetInfo •Metabase W3SVC •ProcMgr •ConfMgr Application Pool – W3WP.exe WebApp •Global •Modules •Handler WebApp •Global •Modules •Handler Cache
  • 12. 12 HTTP.SYS IIS aspnet_isa pi.dll Module HandlerModuleModuleModule
  • 13. 13 HTTP.SYS IIS Module HandlerModuleModuleModule
  • 15. 15  Rule based  UI (IISMGR)  ISAPI extension  Global and distributed rewrite rules  …  It's Infrastructure!
  • 16. 16 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^default.aspx$" /> <conditions> <add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" /> <add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" /> </conditions> <action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" redirectType="Permanent" /> </rule> <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> <match url="^([^/]+)/([^/]+)/?$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="default.aspx?{R:1}={R:2}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
  • 18. 18  IIS URL Rewrite Module updates ASP.NET bugs  "~" is resolved incorrectly when using URL rewriting  SiteMap.CurrentNode property returns null when sitemap contains virtual URLs  Only if the machine has .NET Framework version 3.5 SP1 or higher.  If .NET is installed after URL Rewrite re-install or repair!
  • 19. 19  IIS URL Rewrite Module  x86: http://www.microsoft.com/downloads/details.aspx? FamilyID=836778ea-b2f2-4907-b2dc- a152ec0a4bc4&displaylang=en  x64: http://www.microsoft.com/downloads/details.aspx?f amilyid=6C15B777-8D9E-4D99-B359- A98E2C0880F7&displaylang=en
  • 21. 21  HTTP Handler  HTTP Module
  • 22. 22 public class MyRewriterModule : IHttpModule { public virtual void Init(HttpApplication app) { app.AuthorizeRequest += RewriteRequest; } protected void RewriteRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication) sender; HttpContext.Current.RewritePath("My.aspx?id=42"); } ... }
  • 23. 23 <configuration> <system.web> <httpModules> <add type="MyRewriterModule, App_Code" name="ModuleRewriter" /> </httpModules> <!–- or --> <httpHandlers> <add verb="*" path="*.aspx" type="MyRewriterFactoryHandler, App_Code" /> </httpHandlers> </system.web> </configuration>
  • 25. 25
  • 26. 26  Code your own matching logic   Code your own rule provider   Code your own replace mechanizm 
  • 27. 27  IIS 7 is configured to not authenticate content that is not handled internally  A virtual URL points to an non-existent file  You need to enable URL Authentication on rewriten requests  A) Change preCondition of UrlAuthenticationModule  B) Call Authentication yourself
  • 28. 28
  • 29. 29  A gerneric module to redirect calls to URLs to ASP.NET Page endpoints.  Namespace: System.Web.Routing  Built for the ASP.NET MVC Framework
  • 30. 30 RouteTable is created UrlRoutingModule intercepts the request MvcHandler executes Controller executes RenderView method is executed
  • 31. 31  Each URL Rewrite is defined as entry of the RouteTable.  In MVC the Route Table maps URLs to controllers.  It is setup in the Global.asax
  • 33. 33 <%@ Application Language="C#" %> <script runat="server"> static void RegisterRoutes() { RouteTable.Routes.Add( new Route( "articles", new MyRoutingPageHandler())); } …
  • 34. 34 public class RoutingPageHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { var pathData = requestContext.RouteData.Route.GetVirtualPath( requestContext, requestContext.RouteData.Values); return pathData.VirtualPath.Contains("articles") ? (IHttpHandler)BuildManager. CreateInstanceFromVirtualPath( "~/Default.aspx", typeof(Page)) : (IHttpHandler)BuildManager. CreateInstanceFromVirtualPath( "~/Default2.aspx", typeof(Page)); } …
  • 35. 35 Create and handle routes NOTE: Don't forget to add the required extension if you're trying this with IIS 6…
  • 36. 36
  • 38. 38 var queryString = new StringBuilder("?"); var serverUtil = httpContext.Server; // Copy route data... foreach (var aux in requestContext.RouteData.Values) { queryString.Append(serverUtil.UrlEncode(aux.Key)); queryString.Append("="); queryString.Append( serverUtil.UrlEncode(aux.Value.ToString())); queryString.Append("&"); }
  • 39. 39
  • 41. 41  ASP.NET has no clue that a request is "routed" and authenticates the requested URL – the virtual path 
  • 42. 42 var modules = e.HttpContext.ApplicationInstance.Modules; if (modules["UrlAuthorization"] != null && UrlAuthorizationModule.CheckUrlAccessForPrincipal( e.VirtualPath, e.HttpContext.User, e.HttpContext.Request.HttpMethod)) { return; } if (e.HttpContext.GetAuthenticationMode() != AuthenticationMode.Forms) { return; } e.VirtualPath = FormsAuthentication.LoginUrl; e.QueryString = string.Concat( "?ReturnUrl=", e.HttpContext.Server.UrlEncode( e.HttpContext.Request.RawUrl));
  • 43. 43 Parameters, QueryStrings and FormsAuthentication NOTE: Don't forget to add the required extension if you're trying this with IIS 6…
  • 44. 44
  • 46. 46 public class Form : HtmlForm { protected override void RenderAttributes(HtmlTextWriter writer) { writer.WriteAttribute("name", Name); Attributes.Remove("name"); writer.WriteAttribute("method", Method); Attributes.Remove("method"); Attributes.Render(writer); Attributes.Remove("action"); if (!string.IsNullOrEmpty(ID)) { writer.WriteAttribute("id", ClientID); } } }
  • 47. 47 _context.Response.Filter = new ResponseFilter(_context.Response.Filter); ... public override void Write(byte[] buffer, int offset, int count) { if (HttpContext.Current.Items["VirtualPath"] != null) { var str = Encoding.UTF8.GetString(buffer); var path = HttpContext.Current.Request.Url.PathAndQuery; str = str.Replace( string.Concat( "="", path.Substring(path.LastIndexOf("/") + 1), """), string.Concat( "="", (string)HttpContext.Current.Items["VirtualPath"], """)); buffer = Encoding.UTF8.GetBytes(str); } _sink.Write(buffer, offset, count); }
  • 48. 48
  • 49. 49  URL rewriting is used to manipulate URL paths before the request is handled by the Web server.  The URL-rewriting module does not know anything about what handler will eventually process the rewritten URL.  In addition, the actual request handler might not know that the URL has been rewritten.  ASP.NET routing is used to dispatch a request to a handler based on the requested URL path.  As opposed to URL rewriting, the routing component knows about handlers and selects the handler that should generate a response for the requested URL.  You can think of ASP.NET routing as an advanced handler-mapping mechanism.
  • 50. 50 The presentation content is provided for your personal information only. Any commercial or non-commercial use of the presentation in full or of any text or graphics requires a license from copyright owner. This presentation is protected by the German Copyright Act, EU copyright regulations and international treaties.