user1137472
user1137472

Reputation: 345

How To Hide Edit Page

Hi people am trying to hide the edit page in MVC3 C# so when a user trys to enter "Edit" in the browser some form of page comes up informaing the user this is not allowed.

If you require more information please ask

Thank You

Upvotes: 0

Views: 75

Answers (3)

JP.
JP.

Reputation: 5606

I suggest setting up redirects in your config file. Add the following to system.web in your web.config file and update the redirect path to whatever you want to redirect to..

  <customErrors mode="On" defaultRedirect="Error">
      <error statusCode="302" redirect="Error/PageNotFound" />
      <error statusCode="404" redirect="Error/PageNotFound" />
      <error statusCode="403" redirect="Error/AuthorizationError" />
    </customErrors>

Upvotes: 0

DMulligan
DMulligan

Reputation: 9073

It doesn't sound like you actually want something that specifically handles returning errors for an edit page. It sounds like you want a global way of processing any uncaught errors. Specifically, how to handle 404 errors, AKA errors that happen when a user accesses a page that doesn't exist.

See http://community.codesmithtools.com/CodeSmith_Community/b/tdupont/archive/2011/03/01/error-handling-and-customerrors-and-mvc3-oh-my.aspx for ideas, it includes information on how to handle 404 errors in MVC3.

You shouldn't be getting an error specifically telling you your View doesn't exist unless you created an action with no corresponding View. Given that there is no edit page, if you do have an edit action I would delete it.

Upvotes: 1

Scorpion-Prince
Scorpion-Prince

Reputation: 3634

You can put the [Authorize] attribute on the controller action method.

 [Authorize(Roles = "Admin, Super User")]
 public ActionResult Edit()
 {
     return View();
 }

Upvotes: 0

Related Questions