Malik Kashmiri
Malik Kashmiri

Reputation: 5861

Restrict Action in ASP.Net MVC

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

Upvotes: 0

Views: 115

Answers (1)

Kevin
Kevin

Reputation: 759

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
    //...

}

Upvotes: 2

Related Questions