0

I am trying to restrict the action to not to be called if it has the required parameter available in the url. for example I have a Login Action ut it only be access with it hit on an other web application and it redirect with query string parameter. but it can also be accessible with out parameter I want to restrict this.

Ristrict it

https://localhost:44300/account/login

Right Url

https://localhost:44300/Account/Login?returnUrl=https%3A%2F%2Fdevatea.portal.azure-api.net%2F%2F
4
  • MVC action filters ! Commented Jun 15, 2016 at 12:38
  • 1
    What is the desired action when the parameter doesn't exist? Should it return a 404 error, a 500 error, redirect somewhere or something else? Commented Jun 15, 2016 at 14:44
  • when parameter does not exist it execute the login action but I want this action only be accessible by redirecting to this page by other web app not directly. because when other app redirect the user to login page it return some query string which is important Commented Jun 16, 2016 at 4:20
  • when parameter not exist then it shows 404 eror page Commented Jun 16, 2016 at 4:28

1 Answer 1

2

Based on your requirements, I think the easiest way would be to just add a check to the login action and return a 404 Not Found if the returnUrl is empty or null.

public ActionResult Login(string returnUrl)
{
    if (string.IsNullOrEmpty(returnUrl)) return HttpNotFound();

    //remaining code for login
    //...

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

Comments

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.