Is it possible to access the HttpContext in the ValidationAttribute attribute in ASP.NET MVC?

Can I get HttpContextin ValidationAttributein ASP.NET MVC 3?

I need to check something in my route data for compliance in order to return true on my validator.

thank

+5
source share
2 answers

Yes, you can access the static property HttpContext.Current to get the current http context.

This property can return null depending on which thread you are checking for, or in a request other than http, for example, in unit test.

, , , , , . , HttpContextBase, :

return new HttpContextWrapper(HttpContext.Current);

http .

+6

, RemoteValidationAttribute?

0

All Articles