开发者

Possible bug/issue in ASP.NET 3.5 related to Request.RawUrl property

开发者 https://www.devze.com 2023-01-14 22:12 出处:网络
I posted a query for 301-redirect using ASP.NET 3.5 here: Redirecting default.aspx to root virtual directory

I posted a query for 301-redirect using ASP.NET 3.5 here:

Redirecting default.aspx to root virtual directory

Based on the replies I got there, I realized there might be a bug in ASP.NET's Request.RawUrl method which is unable to return the actual raw url (without /default.aspx) when being used in a sub-directory, i.e. the /default.aspx page is inside a subdirectory.

Can someone 开发者_高级运维please shed some light on this possible bug?

Thanks,

Asif


i found a good explanation here

http://codeasp.net/blogs/vivek_iit/microsoft-net/873/301-redirect-from-default-aspx-to-site-root

Thanks


If you suspect this is a bug, then the place to go is Microsoft Connect, where you can report and discuss the bug directly with Microsoft.

Edit: I was able to reproduce the look per your comments.

I was unable to reproduce the infinite loop, however. I injected code into the Global.asax Application_BeginRequest handler of a web application and got the expected behavior of a single redirect.

There are other, and IMO much better, options for handling global redirect rules. On IIS7, I use the URL Rewrite module to configure rewrite rules in IIS. You can read more about it and download it here: http://www.iis.net/download/urlrewrite. The appeal of a solution such as this is that you can customize and update your rewrite rules without recompiling the application.

Edit: I was able to retrieve the raw URL without the default.aspx (after the redirect) by using instead:

Request.ServerVariables["CACHE_URL"]

It's worth a shot.


Have you looked at the IIS settings for your virtual directory? If there is a default document set to default.aspx then this will explain the infinite loop that you are experiencing. You are telling the website to redirect to the virtual directory without the "default.aspx" and IIS is detecting this on the next request and putting it back in ad infinitum.

Right click your virtual directory, select Properties and then the Documents tab. If default.aspx is in the list then that is what you will get. The Url of the request will be passed to the ASP.NET worker process as /folder/default.aspx rather than /folder/

This is not a bug. If IIS didn't do this, you would get a page not found error.

Sounds to me like you need to investigate URL rewriting: http://msdn.microsoft.com/en-us/library/ms972974.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消