开发者

Response.Redirect ReturnUrl

I'm trying to use Response.Redirect on an ASP.NET page that uses routing and membership -- in order to redirect non logged in users to the main page. This is a page that should sometimes be viewable to anonymous users based on content. When I redirect to the login page, the browser fills the returnurl with invalid content.

The question is how do I remove the ReturnURL before sending the user "off"? Or how do I fix it so that it includes the proper link?

The page is in a different directory. It redirects properly but sets the ReturnURL to an invalid path.

The ReturnUrl is just set to the folder. Not to the page with query params nor do the route.

UPDATE

Okay where is what it is doing

I have a folder Actions. I'm redirecting to Login.aspx. It redirects to login.aspx but then sets the returnurl to Actions/Login.aspx which is absolutely wrong.

It is wrong on 2 accounts:

  1. The login.aspx doens't exist开发者_Python百科 in the actions folder
  2. It creates a recursive redirect

Update Fixed Partially

Okay, it was because I was in a different folder and not redirecting to the proper page.

I had "login.aspx" instead of "../login.aspx"

However, it is not setting the returnurl to the routed path. It is stripping the returnurl. I may have decided to do this as a design decision though, not 100% sure.


I have not understood the nitty gritty of the issue you are facing, but I guess you might have missed to apply Server.UrlEncode to return url. Please have a look at what Server.UrlEncode does at

http://msdn.microsoft.com/en-us/library/ms525738(v=vs.90).aspx

Below is the piece of code which shows how specify Return Url using Server.UrlEncode

Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + 
Server.UrlEncode(Request.Url.ToString()))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜