Bad Request Error 400 on IIS7 .NET 3.5

南楼画角 提交于 2019-12-13 03:36:38

问题


I am running into a bad request error 400 on IIS7. I have encoded special characters in the URL string. My URL's look something like this (doesn't like %26):

http://www.myjobs.com/a/q-Barnes+%26+Noble

This would be an easy fix if I were running on .NET 4.0, but I am on rackspace cloud and can only run on IIS7 .NET 3.5.

This is what I would use in my web.config if I were on IIS7 .NET 4.0:

requestPathInvalidCharacters=""

What other options are there when running on IIS7 and .NET 3.5?


回答1:


The only way you can make requests like that is if you change the registry. For IIS running in 32 bit mode, add the following DWORD key and set its value to 1 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\VerificationCompatibility

If you're running IIS in 64 bit mode, add the following DWORD key and set its value to 1 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\VerificationCompatibility

Not sure if your hosting enviornment will give you access to that stuff. I tested it on IIS 7.5 and was able to make a request to /Barnes&Noble/default.aspx using a URL encoded like this: Response.Redirect(Server.UrlEncode("Barnes&Noble") + "/default.aspx");




回答2:


Why encode special characters into the URL at all?

Why not convert them all to a more SEO-friendly form that has only alphanumeric characters and dashes and store that special form in your database. Or, even easier, include the ID in the URL and use the latter part just to make it human readable and SEO-friendly:

e.g. www.myjobs.com/a/1234/q-Barnes-and-noble

This approach also means you can change your encoding later (maybe add some new special character to alpha mapping) and not have any 404's.



来源:https://stackoverflow.com/questions/3543850/bad-request-error-400-on-iis7-net-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!