SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

En vedette

En vedette (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
 

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

ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 
Hdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed SolutionsHdv309 - Real World Sandboxed Solutions
Hdv309 - Real World Sandboxed Solutions
woutervugt
 
Playing with php_on_azure
Playing with php_on_azurePlaying with php_on_azure
Playing with php_on_azure
CEDRIC DERUE
 

Similaire à 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
 

Plus de Daniel Fisher

2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET
Daniel Fisher
 

Plus de 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
 

Dernier

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Dernier (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

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.