URL olarak kodlanmış URL eğik çizgi
Benim Harita:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with params
new { controller = "Home", action = "Index", id = "" } // Param defaults
);
Eğer URL http://localhost:5000/Home/About/100/200
kullanırsam eşleşen yol yok.
http://localhost:5000/Home/About/100
sonra yönlendirmek için URL yeniden eşleştirilir değiştirdim.
Herhangi bir kolay yolu eğik çizgi içeren parametreleri ile çalışma var mı? Diğer kaçmış değerleri (alanı
) çalışmıyor gibi görünüyor.
DÜZENLEME:
Base64 kodlamak benim için çalışıyor. URL çirkin yapar, ama bunun için artık sorun değil.
public class UrlEncoder
{
public string URLDecode(string decode)
{
if (decode == null) return null;
if (decode.StartsWith("="))
{
return FromBase64(decode.TrimStart('='));
}
else
{
return HttpUtility.UrlDecode( decode) ;
}
}
public string UrlEncode(string encode)
{
if (encode == null) return null;
string encoded = HttpUtility.PathEncode(encode);
if (encoded.Replace(" ", "") == encode.Replace(" ", ""))
{
return encoded;
}
else
{
return "=" ToBase64(encode);
}
}
public string ToBase64(string encode)
{
Byte[] btByteArray = null;
UTF8Encoding encoding = new UTF8Encoding();
btByteArray = encoding.GetBytes(encode);
string sResult = System.Convert.ToBase64String(btByteArray, 0, btByteArray.Length);
sResult = sResult.Replace(" ", "-").Replace("/", "_");
return sResult;
}
public string FromBase64(string decode)
{
decode = decode.Replace("-", " ").Replace("_", "/");
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetString(Convert.FromBase64String(decode));
}
}
EDİT1:
Sonunda en iyi yolu seçmek için ihtiyacım olan her öğe için güzel format bir dize kurtarmak için olduğu ortaya çıktı. Şimdi Thats ben sadece değerlerini kodlamak ve asla onları deşifre olduğundan çok daha iyi. Tüm özel karakterler " - " hale gelir. Db tabloları şimdi benim bir sürü bu ek sütun var "" URL Veriler oldukça kararlı olduğunu, bu şekilde devam edebilirim bu yüzden. Hatta, "eşsiz." URL verileri kontrol edebilirim
EDİT2:
Ayrıca boşluk karakteri dikkat edin. VS Entegre Web sunucusu üzerinde iyi görünüyor ama *ııs7* 9 farklı
CEVAP
Eğer sadece son parametre ise, yapabilirsiniz:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{*id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" }); // Parameter defaults
Önde gelen çift eğik çizgi üzere bir U...
Tire, alt çizgi veya URI sözcük ayırıc...
ASCII dize düz ASCII Hex olarak kodlan...
String.replaceAll çift ters eğik çizgi...
Neden't Python'ham dize hazı...