2010-05-14 4 views
1

내 MS SQL 서버에서로드 된 ASP.NET 4.0 동적 페이지를 만들고 싶습니다. 기본적으로 정보가있는 위치 목록입니다. 예 :ASP.NET 4.0 데이터베이스 생성 페이지

Location1 would have the page www.site.com/location/location1.aspx 
Location44 would have the page www.site.com/location/location44.aspx 

어디서부터 시작해야할지 모르겠습니까?

+0

니 달성하고자하는 것에 대해 더 자세히 설명해주십시오. –

답변

2

URL 재 작성은 설명하는 것과 다른 문제를 해결합니다.

경로 location에 대한 요청을 처리하고 마지막 세그먼트를 구문 분석하여 조회 키를 얻은 HttpHandler를 사용하여 실행을 .aspx에 전달할 수 있습니다. 실행을 일반 페이지로 전달하더라도 URL은 입력 된 그대로 유지됩니다.

예제를 제공합니다. 한번 해봐. here is a sample project

LocationHandler.cs

using System.IO; 
using System.Web; 

namespace DBHandler 
{ 
    public class LocationHandler : IHttpHandler 
    { 
     #region IHttpHandler Members 

     public void ProcessRequest(HttpContext context) 
     { 
      HttpRequest request = context.Request; 
      string page = Path.GetFileNameWithoutExtension(request.Url.Segments[request.Url.Segments.Length - 1]); 

      // for url ~/location/location33.aspx page will be 'location33' 

      // do something interesting with page, perhaps 
      context.Server.Execute("~/locations.aspx?locationId=" + context.Server.UrlEncode(page)); 
     } 

     public bool IsReusable 
     { 
      get { return false; } 
     } 

     #endregion 
    } 
} 

locations.aspx

<%@ Page Language="C#" %> 

<script runat="server"> 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     Label1.Text = Request["locationId"]; 
    } 
</script> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    </div> 
    </form> 
</body> 
</html> 

Web.config의 발췌

... 
<system.web> 
    ... 
    <httpHandlers> 
    <add verb="*" path="location/*.*" type="DBHandler.LocationHandler"/> 
    </httpHandlers> 
</system.web> 
...