[英]special character in url routing in asp.net 4.0 web form?
在 asp.net 4.0 中使用 url 路由時如何處理 url 中的特殊字符?
特殊字符,例如 ( &, .)
它在 url 中將錯誤顯示為錯誤請求或危險字符。
怎么處理?
假設我在 Global.asax 文件中有 url 路由
protected void Application_Start(object sender, EventArgs e)
{
CustomRouteTable(RouteTable.Routes);
}
void CustomRouteTable(RouteCollection routes)
{
routes.MapPageRoute("Product", "Product/{pId}/{ProductName}", "~/Product/ProductDetail.aspx");
}
假設 productName 是 Phone&Cordless 或 Phone:Cordless 然后我得到錯誤。
怎么處理?
您真的應該遠離在不用於處理查詢字符串參數的 URL 中使用與號。 考慮在 URL 的產品名稱中使用“-and-”。
URL has a special kind of encoding which is called URL Encoding and almost every web programming language (including JavaScript) has a way to encode and decode strings into and out from URL encodes strings. 正如@rkaregaran 所說,我也強烈建議您在 URL 中使用-
(破折號)或_
(下划線)。
無論如何,正如我在您的解釋中看到的那樣,我認為您應該使用/phone/cordless
而不是phone:cordless
。 似乎這里的phone
是一種分類法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.