我有一个项目,要求我的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项目,但我不认为这是相关的.我的路由工作正常,我期望的参数在那里,直到它们包含一个点.
我需要配置什么才能在网址中加点?
我有一个WebApi控制器,其方法如下:
[HttpGet]
[AcceptVerbs("GET")]
public HttpResponseMessage Run(string reportName, int someId, string someText, DateTime asOfDate, string username)
Run Code Online (Sandbox Code Playgroud)
我有专门为此操作配置的自定义路由.当我将浏览器导航到Web服务时,一切正常,并执行相应的操作:
http://localhost:xxxx/ControllerName/Run/asdf/1/asdf/07-01-2012/user@domain.com
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用HttpClient以编程方式调用Web服务并执行"获取"时,我收到404错误.当username参数不是电子邮件地址时,我不会收到错误.例如,当用户名只是"用户"时,一切正常.以下是示例代码:
var url = "http://localhost:xxxx/ControllerName/Run/asdf/1/asdf/07-01-2012/user@domain.com"
var client = new System.Net.Http.HttpClient();
var response = client.Get(url);
//fails here with 404 error
response.EnsureSuccessStatusCode();
Run Code Online (Sandbox Code Playgroud)
我试过UrlEncoding电子邮件地址没有运气.任何建议表示赞赏.
我正在从原始的http处理程序移动API项目,我在路径中使用句点:
http://server/collection/id.format
Run Code Online (Sandbox Code Playgroud)
我想在Web Api(自托管)版本中遵循相同的URL架构,并尝试这样做:
var c = new HttpSelfHostConfiguration(b);
c.Routes.MapHttpRoute(
name: "DefaultApiRoute",
routeTemplate: "{controller}/{id}.{format}",
defaults: new { id = RouteParameter.Optional, format = RouteParameter.Optional },
constraints: null
);
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎没有解决(在/ foo,/ foo/bar和/foo/bar.txt上一致的404').在'format'之前使用斜杠的类似模式工作正常:
var c = new HttpSelfHostConfiguration(b);
c.Routes.MapHttpRoute(
name: "DefaultApiRoute",
routeTemplate: "{controller}/{id}/{format}",
defaults: new { id = RouteParameter.Optional, format = RouteParameter.Optional },
constraints: null
);
Run Code Online (Sandbox Code Playgroud)
我还没有深入研究Web Api的代码,在此之前我想过我会在这里询问这是否是Web Api中已知的,甚至是合理的限制.
更新:我忽略了提到"id"和"format"是字符串,这对于解决这个问题很重要.添加约束以从"id"标记中排除句点可解决404问题.
我正在使用.net4.5rc和MVC4.0rc
下面的代码来自MVC webapi应用程序,但我对reular asp.net mvc的行为相同
我的registerroutes代码看起来像这样
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "R1",
routeTemplate: "product/{id}",
defaults: new {
controller="Product",
id = RouteParameter.Optional
}
);
Run Code Online (Sandbox Code Playgroud)
这适用于没有句号的Ids.但是,当我要求一个带有句号的产品时,调用似乎没有进入ASP.NET
当我在类似的帖子上使用下面的设置时,它会在有尾随时起作用/但如果没有它就不起作用
综上所述
http://mysite.com/product/AZ0 //works
http://mysite.com/product/AZ.0/ //work with relaxedUrlToFileSystemMapping
http://mysite.com/product/AZ.0 //does not work
Run Code Online (Sandbox Code Playgroud)
响应是404,我想这是由IIS返回的,不涉及ASP.NET.当我用上面的最后一个URL运行routedebugger时,我甚至没有得到routedebugger的东西
当存在带有模式的URL时,如何使IIS将控件传递给ASP.NET:mysite.com/product/{id},无论id是否有句点.
谢谢.
我有一个 Blazor 服务器应用程序,其中一个页面接受 uri 中的参数。当我单击具有路由设置的锚标记以使用参数(如下所示)访问该页面时,链接工作正常,并且页面加载。
<a href="/MyPage/{@Param1}/{@Param2}"> <!--link content in here--> </a>
Run Code Online (Sandbox Code Playgroud)
但是,如果尝试直接从该 URL 访问该页面,或者在浏览器中手动刷新,则该页面不会重新初始化或命中参数上的任何断点。相反,它会抛出 404 not found。
所以这里有两件事:
@page可以与刷新/直接网址一起正常工作时。相关页面的 Razor 和 Razor.cs:
@page "/MyPage/{Param1}/{Param2}"
<h1>MyPage</h1>
<Metrics Param1="@Param1" />
<Details Param1="@Param1" Param2="@Param2" />
<InProgress Param1="@Param1" Param2="@Param2" />
<InQueue Param1="@Param1" />
<br />
Run Code Online (Sandbox Code Playgroud)
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using MyApp.Data.Models.ApiResponse;
namespace MyApp.Pages
{
public partial class MyPage
{
[Parameter]
public string Param1 { get; set; …Run Code Online (Sandbox Code Playgroud) 我运行MVC 5,并有一个搜索API产生以下链接:/SearchedItem.?format=json这里SearchedItem.是用户输入的搜索.由于一个dot角色,这显然会导致着名的404 .我已经研究了以下所有解决方案:
点字符'.' 在MVC Web API 2中请求诸如api/people/STAFF.45287之类的请求
然而,无论是加斜杠(尝试都/SearchedItem./?format=json和/SearchedItem.?format=json/),也不RAMMFAR工作.
寻找任何新的建议.
我有一个 Asp.Net Web Api 应用程序,它以 ip 地址作为输入并返回相应 ip 的国家/地区。当我通过以下网址时
http://localhost:portno/xx.xx.xx.xx
Run Code Online (Sandbox Code Playgroud)
它抛出 Error 404
谁能告诉我为什么?
asp.net-mvc ×4
c# ×4
iis ×3
api ×1
asp.net ×1
blazor ×1
iis-7 ×1
iis-7.5 ×1
iis-8 ×1
iis-express ×1
page-refresh ×1
url ×1