Asp.net 4.0 ルーティング手法を使用して、わかりやすい URL を実現しました。global.asax で次のコードを使用しました。
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionstring);
SqlCommand sqlCmd = new SqlCommand("Sch_Sp_GetRegisterRoutes", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
try
{
sda.Fill(dt);
}
catch (Exception ex)
{
}
finally
{
sqlCon.Close();
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
try
{
routes.MapPageRoute(dr["Menuname"].ToString().Replace(" ",string.Empty),
dr["URL"].ToString(),
"~/" + dr["Pagename"].ToString());
}
catch (Exception exx)
{
}
}
}
}
データベース内の私の URL は About-Us のようなもので、ページ名は MyFolder/Aboutus.aspx のようなものです。ローカル マシンでは機能しましたが、サーバー (iis 7 バージョンおよび Windows Server 2008) に展開すると、エラー ' 404 - ファイルまたはディレクトリが見つかりません。お探しのリソースは、削除されたか、名前が変更されたか、一時的に利用できない可能性があります。私を助けてください....