我有一个项目,要求我的URL在路径中有点.例如,我可能有一个URL,例如www.example.com/people/michael.phelps
带点的网址生成404.我的路由很好.如果我通过michaelphelps,没有圆点,那么一切正常.如果我添加点我得到404错误.示例站点在带有IIS8 Express的Windows 7上运行.URLScan未运行.
我尝试将以下内容添加到我的web.config中:
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有什么区别.我刚收到404.0 Not Found错误.
这是一个MVC4项目,但我不认为这是相关的.我的路由工作正常,我期望的参数在那里,直到它们包含一个点.
我需要配置什么才能在网址中加点?
我试图让工作的URL是以下风格的网址:http://somedomain.com/api/people/staff.33311(就像网站一样,LAST.FM允许在他们的RESTFul和WebPage网址中添加所有类型的标记例如," http://www.last.fm/artist/psy'aviah "是LAST.FM的有效网址.
以下方案有效: - http://somedomain.com/api/people/ - 返回所有人 - http://somedomain.com/api/people/staff33311 - 也可以,但不是我的意思在我希望网址接受"点"后,就像下面的示例 - http://somedomain.com/api/people/staff.33311 - 但这给了我一个
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Run Code Online (Sandbox Code Playgroud)
我已经设置了以下内容:
控制器"PeopleController"
public IEnumerable<Person> GetAllPeople()
{
return _people;
}
public IHttpActionResult GetPerson(string id)
{
var person = _people.FirstOrDefault(p => p.Id.ToLower().Equals(id.ToLower()));
if (person == null)
return NotFound();
return Ok(person);
}
Run Code Online (Sandbox Code Playgroud)WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
// …Run Code Online (Sandbox Code Playgroud)c# asp.net-mvc-routing asp.net-mvc-4 asp.net-web-api asp.net-web-api2
我有一个ApiController,我想使用电子邮件地址作为请求的ID参数:
// GET api/employees/email@address.com
public CompactEmployee Get(string id) {
var email = id;
return GetEmployeeByEmail(email);
}
Run Code Online (Sandbox Code Playgroud)
但是,我不能让它工作(返回404):
http://localhost:1080/api/employees/employee@company.com
以下所有工作:
http://localhost:1080/api/employees/employee@companyhttp://localhost:1080/api/employees/employee@company.http://localhost:1080/api/employees?id=employee@company.com我已经设置relaxedUrlToFileSystemMapping="true"了我的web.config,详见Phil Haack.
我非常喜欢完整的电子邮件地址,但是任何时候任何其他角色跟着这个时期,请求都会返回404.任何帮助都将非常感谢!
由于缺乏其他选项,我已朝着Maggie建议的方向前进,并使用此问题的答案来创建重写规则,以便在我需要URL中的电子邮件时自动附加尾部斜杠.
<system.webServer>
....
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(api/employees/.*\.[a-z]{2,4})$" />
<action type="Rewrite" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)