user459611
user459611

Reputation:

how to detect asp.net webforms page?

if a page contains a Viewstate in the source. Does this mean the webpage is using ASP.NET WebForms or could this also be an MVC project ?

Thanks!

Upvotes: 0

Views: 527

Answers (2)

Niranjan Singh
Niranjan Singh

Reputation: 18260

Source: ASP.NET MVC and Web Forms Integration

IIS needs to be able to figure out whether a given request is an ASP.NET MVC or a Web Forms request. Once it can figure that out, IIS can send the request to the appropriate handler and the application behaves as you’d expect.

check these lines from that nice article.

Caution

Watch out for ViewState! Though many parts of the ASP.NET Framework are accessible by both Web Forms and ASP.NET MVC, the most significant piece of the Web Forms Framework that is not supported in ASP.NET MVC at all is ViewState. Most often, ViewState is used for a Web Forms Page to communicate with itself, so the chances of running into ViewState issues when cross-posting between Web Forms pages and ASP.NET MVC controllers are slim.

However, when transitioning your Web Forms application to ASP.NET MVC, be on the lookout for any code in your Web Forms application that expects ViewState — the ViewState data will not exist during the course of an ASP.NET MVC request so code that depends on it will likely break!

Upvotes: 1

M4N
M4N

Reputation: 96626

There is no ViewState in MVC. So if you find a ViewState element, you can be pretty sure that it's an ASP.NET WebForms page.

Although, since ViewState is just a regular hidden input element with name/id "__VIEWSTATE", there is a slight chance, that someone added such an element (in a non-ASP.NET page) with exactly that name and id:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
  value="contents go here" />

Upvotes: 0

Related Questions