質問

MS SQL Serverからロードされた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

これからどこから始めればいいのかさえ知りません。

役に立ちましたか?

解決

URL書き換えは、あなたが説明しているものとは異なる問題に対処します。

リクエストをパスに処理するhttphandlerを使用できます location 最後のセグメントを解析してルックアップキーを取得し、実行を.aspxに渡すだけです。実行を一般的なページに渡していますが、URLは入力されたままです。

例を提供します。試してみます。 これがサンプルプロジェクトです

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>
...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top