ASP.NET URL Rewriting - 1
Posted 2008-05-14 at 10:48 by DincerAydogdu
Öncelikle bir HttpModule yazmamız gerekmektedir. Örneği altta bulabilirsiniz:
IIS isapi filterdan geçen her istek buraya uğrar. Bunu httpmodule olarak set etmek için web.config file'indaki system.web altına yukarıdaki xmli ekleyin. Kodda gerekli açıklamalar vardır. Siz http://sunucun/xyzt.aspx dediğiniz zaman http://sunucun/test.aspx?parametre=xyzt response verecektir.
Kod:
Imports Microsoft.VisualBasic
Imports System.Web
Public Class SimpleRewriter
Implements System.Web.IHttpModule
Dim WithEvents _application As HttpApplication = Nothing
Public Overridable Sub Init(ByVal context As HttpApplication) _
Implements IHttpModule.Init
_application = context
End Sub
Public Overridable Sub Dispose() Implements IHttpModule.Dispose
End Sub
Public Sub context_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) _
Handles _application.BeginRequest
'Request.Path bize kullanıcının istediği pathi verir.
'Bu pathi alıp gonderilmek istenilen parametre ayıklanır
'Örn : http://domain.com/cicekler_bocekler.aspx örneği için almak istediğimiz cicekler_bocekler olsun.
Dim CurrentPath As String = _application.Context.Request.Path
Dim Parametre As String = CurrentPath.Substring(CurrentPath.LastIndexOf("/"c) + 1, CurrentPath.Length - CurrentPath.LastIndexOf("/"c) - 1)
'Standart kurulumda isapi filtera takılan dosyalar düşer (.aspx, .asmx) gibi. Özel bir iis isapi ayar yapmadıkça bu condution geçerliliğini koruyacaktır.
If Parametre.Contains(".") Then
Parametre = Parametre.Substring(0, Parametre.LastIndexOf("."))
End If
'Test.aspx burada senin processorundur.
_application.Context.RewritePath("~/Test.aspx?Parametre=" & Parametre)
'Gerisi tamamen hayal gücünün genişliğine kalmış. Artık regular expression mu kullanırsın case mi koyarsın. Sana bağlı.
End Sub
End Class
Kod:
<httpModules>
<add name="SimpleRewriter" type="SimpleRewriter, App_code" />
</httpModules>
Total Comments 0
Comments
Post a Comment
|
Recent Blog Entries by DincerAydogdu
- ASP.NET URL Rewriting - 1 (2008-05-14)







