MVC4:网址与电子邮件作为参数路由 [英] MVC4: url routing with email as parameter
问题描述
我有这个网址这工作绝对没我的VS Web服务器上
I have this url which works absolutely fine on my VS web server
http://localhost:4454/cms/account/edituser/email@domain.com (works)
但是当我发布这个网站IIS7。 5,它只是抛出404。
but when I publish this site to IIS7.5 , it simply throws 404.
http://dev.test.com/cms/account/edituser/email@domian.com (does not work)
但如果我删除的电子邮件地址的奇怪的事情发生了。
but the strange things happens if I remove email address
http://dev.test.com/cms/account/edituser/email (works , no 404)
但如果我改变我的网址查询字符串,它工作正常。
but if I change my url with query string it works fine
http://dev.test.com/cms/account/edituser?id=email@domain.com (works)
这是我的路由条目
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "App.NameSpace.Web.Controllers" }
);
我已经注意到奇怪的是,当服务器引发404错误页面,这是一个标准的iis 404页不是一个自定义我有。结果,所以我想知道有没有用我的路由映射
或IIS任何问题,不喜欢具有电子邮件作为参数的URL。但一切都正常工作与我的本地开发。
结果
谢谢
weird thing I have noticed is that when server throws 404 error page , it is a standards iis 404 page not the one custom one I have.
so I was wondering is there any issue with my route mapping
or IIS does not like the url which has email as parameter. but everything works fine with my local dev.
Thanks
推荐答案
尝试URL编码的URL的电子邮件地址。
Try url encoding the email address in the URL.
修改
以UrlEncode + Base64的?
UrlEncode + Base64?
public static string ToBase64(this string value)
{
byte[] bytes = Encoding.UTF8.GetBytes(value);
return Convert.ToBase64String(bytes);
}
public static string FromBase64(this string value)
{
byte[] bytes = Convert.FromBase64String(value);
return Encoding.UTF8.GetString(bytes);
}
在您的视图:
<a href="@Url.Action("MyAction", new { Id = email.ToBase64() })">Link</a>
在控制器
function ActionResult MyAction(string id){
id = id.FromBase64();
//rest of your logic here
}
这篇关于MVC4:网址与电子邮件作为参数路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!