Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a webmethod in codebehind as secure as the page it is on?

Tags:

c#

asp.net

This is kind of confusing me. I would assume the webmethod would follow the same authorization rules set in the web.config as the page it is on. Will it execute the normal page lifecycle first? In my case there is extra logic in a basepage that checks further permissions. Will this logic be executed before the webmetod is called to prevent access from users not permitted to access that page?

like image 961
Mike Avatar asked Aug 23 '11 12:08

Mike


2 Answers

A webmethod must be static and it does not follow the normal ASP.NET lifecycle.

In a webmethod, you can't access the session or the controls on the page.

Since it won't go through all the events, I don't think your PreInit will be called so you won't be able to restrict access through that.

like image 97
Martin Avatar answered Oct 22 '22 08:10

Martin


Bottom line is a web method is much less secure than using the tradition asmx web method. Even though you may have the method hanging of /default.aspx/MyWebMethod, it will not take on any of the built in forms security and can be called from anywhere in your application.

like image 37
Donnie Avatar answered Oct 22 '22 09:10

Donnie