开发者

Difference between Server.MapPath and Page.MapPath

开发者 https://www.devze.com 2023-01-17 01:22 出处:网络
W开发者_如何学JAVAhat is the difference between those two? If I only want to retrieve the absoluate path to an image on web server, is Server.MapPath safer in any case?

W开发者_如何学JAVAhat is the difference between those two? If I only want to retrieve the absoluate path to an image on web server, is Server.MapPath safer in any case? I'm using Page.MapPath right now, but it won't work if control was created in WebService since control.Page property become null? Whether Server.MapPath always work?


I have seem through Reflector and it seems both methods end up calling the same base method.

So you can use whichever fits better.

If you don't have the Page, you can get it through the context handler. (It will be null if you are not actually in a page).

var Page = HttpContext.Current.Handler as Page;
0

精彩评论

暂无评论...
验证码 换一张
取 消