如何在ASP.NET MVC Web API的URL末尾将电子邮件作为参数传递?
如何在ASP.NET MVC Web API的URL末尾将电子邮件作为参数传递?如何在ASP.NET MVC Web API的URL末尾将电子邮件作为参数传递?
象下面这样:
我想传递的电子邮件地址作为参数传递给getcustomerorders行动。
我们可以通过使用查询字符串。但我想像上面那样格式化网址。
谢谢。
在WebApiConfig中将路由设置为“/ {email} /”。结尾“/”将阻止您获取没有找到与请求URI相匹配的HTTP资源...
这里的问题是,你有期限的网址。
为了使其工作,改变你的web配置中添加以下两种配置:
<configuration>
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Haacked有一个关于relexUrlToFileSystemMapping http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx
博客,我有一个bug它在IIS中表达8并需要runAllManagedModulesForAllRequests: https://aspnetwebstack.codeplex.com/workitem/226
它的作品,但如果你参考[这个链接](http://stackoverflow.com/questions/11048863/modules-runallmanagedmodulesforallrequests-true-意味)它会减慢你的应用程序,因为你加载所有模块的所有请求.. – davidlebr1
只是runAllManagedModulesForAllRequests需要允许一个电子邮件地址,因为在URL中使用了句点 – user2320464
您必须在URL中编码@符号,因为它是保留字符。应该看起来像这样:test.com/api/sales/getcustomerorders/test%40test.com –
我在这里尝试了相同的URL(用@),它的工作原理..什么错了? – MuriloKunze
这是问题的DOT。 –