0

I am developing an Asp.net MVC project. I am having a problem with redirect url.

I have a link like this.

<a href="@Url.Content("~/Account/Login&ReturnUrl="+Url.Encode(Request.Url.PathAndQuery))">Log in</a>

You can see I added a ReturnUrl query value to the end of url because I want to redirect the user to current url after login.

Request.Url.PathAndQuery return string like this

/Item/Details?name=test&id=4

When I click the link, it is giving me error:

The request filtering module is configured to deny a request that contains a double escape sequence.

Url value is like this:

http://localhost:50489/Account/Login&ReturnUrl=%2fItem%2fDetails%3fname%3dtest%25203%26id%3d4

I cannot use Html.ActionLink because I need to add some html content inside anchor tag.

How can I pass current URL to as ReturnUrl value to log in page?

1 Answer 1

1

Your URL is incorrectly formatted. A query string must begin with a ?, not a &.

<a href="@Url.Content("~/Account/Login?ReturnUrl="+Url.Encode(Request.Url.PathAndQuery))">Log in</a>

& is for separating query string arguments within the query string.

Sign up to request clarification or add additional context in comments.

1 Comment

Opps! Thanks so much. My mistake and weakness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.