ASP.NET URL验证

前端之家收集整理的这篇文章主要介绍了ASP.NET URL验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们在ASP.NET上有一个定制的REST处理程序,它被配置为处理所有传入的请求:
<add path="*" verb="*" type="REST.RESTProtocolHandler"/>

但是,传递一个管道字符,正确的编码或根本不会触发一个似乎来自ASP.NET内部的验证错误.

访问http://localhost:8080/%7chttp://localhost:8080/|会导致此错误

[ArgumentException: Illegal characters in path.]
System.IO.Path.CheckInvalidPathChars(String path) +7489125
System.IO.Path.Combine(String path1,String path2) +40
System.Web.Configuration.UserMapPath.GetPhysicalPathForPath(String path,VirtualDirectoryMapping mapping) +114
System.Web.Configuration.UserMapPath.GetPathConfigFilename(String siteID,VirtualPath path,String& directory,String& baseName) +72
System.Web.Configuration.UserMapPath.MapPath(String siteID,VirtualPath path) +30
System.Web.Configuration.UserMapPath.MapPath(String siteID,String path) +31
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath,Boolean permitNull) +297
System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath,Boolean permitNull) +51
System.Web.CachedPathData.GetConfigPathData(String configPath) +341
System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath,Boolean permitPathsOutsideApp) +110
System.Web.HttpContext.GetFilePathData() +36
System.Web.HttpContext.GetConfigurationPathData() +26
System.Web.Configuration.RuntimeConfig.GetConfig(HttpContext context) +43
System.Web.Configuration.CustomErroRSSection.GetSettings(HttpContext context,Boolean canThrow) +41
System.Web.HttpResponse.ReportRuntimeError(Exception e,Boolean canThrow,Boolean localExecute) +101
System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr,HttpContext context,Exception e) +383

没有用户地址代码被执行.这是一个配置选项吗?转载于IIS 7& VS Studio的2008 devel服务器.

堆栈溢出似乎处理这个错误OK,它看起来像一个动态生成404 MVC页面渲染为https://stackoverflow.com/%7c.

有任何想法吗?

解决方法

尝试拦截Global.asax文件中的异常.实现那里(Global.asax.cs)这个方法
protected void Application_Error(Object sender,EventArgs e)
{
    Exception ex = Server.GetLastError();
    //do whatever you want with that exception
    //or get the url from the context,reformat and redirect
}

猜你在找的asp.Net相关文章