February 5, 2007
@ 12:18 AM

Genelde içeriği bol olan sitelerde http://.../hede/hode/1 (*) gibi linklerin olduğunu görürüz. Bizler ise gendle http://.../hede/hode.aspx?bisi=1 gibi QueryString ifadelerinden yararlanarak içeriği kullanıcıya yansıtırız.


Peki asp.net'te (*) daki gibi bir kullanımı nasıl sağlarız. Bunun için HttpHandler dan yararlanmak lazım - dikkat ederseniz uzantı yok url'de. Bu durumda IIS hemen 404 hatasını yollayacaktır kullanıcıya-  Ama birçoğumuz sitelerimizde IIS'a müdahale edemiyoruz. Peki ne yapabiliriz bu durumda. En iyisi bir HttpModule yazıp linklerimizi http://.../hede/hode/1.aspx şeklinde düzenleyebiliriz. (Aslında yapmak istediğimiz http://.../hede/hode.aspx?bisi=1 dir.) Bunun için HttpContext sınıfının RewritePath metodundan yararlanabiliriz. HttpModule konusu ile ilgili bilgileri şurdaki linkten edinebilirsiniz.


using System;

using System.Collections.Generic;

using System.Text; using System.Web;

namespace rewmod

{

class hede : IHttpModule

{

public void Dispose(){}

public void Init( HttpApplication context ) {

    context.BeginRequest += new EventHandler(context_BeginRequest);

}

void context_BeginRequest( object sender, EventArgs e ) {

    string makalePattern = "makale/";

    string oldUrl = HttpContext.Current.Request.Path;

    int startIndex = oldUrl.IndexOf(makalePattern);

    if (startIndex != -1) {

        int endIndex = oldUrl.IndexOf(".aspx");

    if (endIndex != -1) {

        startIndex += makalePattern.Length;

    string makaleNumber = oldUrl.Substring(startIndex, endIndex - startIndex);

    HttpContext.Current.RewritePath("~/amac.aspx?id=" + makaleNumber);

}

}

}

}

}


web.config içeriği.

..

<system.web>

    <httpModules>

        <add name="hede" type="rewmode.hede"></add>

    </httpModules>

....


 
Friday, November 06, 2009 3:45:25 AM (GTB Standard Time, UTC+02:00)
Do you want to buy some sheepskin boots, please come to www.findugg.com.Full range of UGG boots for Men and Women to buy online. Fast and free shipping to worldwide, competitive price, high quality, and efficient service.

Read more:http://www.findugg.com
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview