12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Web;
- namespace Senparc.Weixin.MP.Sample.CommonService.Utilities
- {
- public static class Server
- {
- private static string _appDomainAppPath;
- public static string AppDomainAppPath
- {
- get
- {
- if (_appDomainAppPath == null)
- {
- _appDomainAppPath = HttpRuntime.AppDomainAppPath;
- }
- return _appDomainAppPath;
- }
- set
- {
- _appDomainAppPath = value;
- }
- }
- public static string GetMapPath(string virtualPath)
- {
- if (virtualPath == null)
- {
- return "";
- }
- else if (virtualPath.StartsWith("~/"))
- {
- return virtualPath.Replace("~/", AppDomainAppPath).Replace("/", "\\");
- }
- else
- {
- return Path.Combine(AppDomainAppPath, virtualPath.Replace("/", "\\"));
- }
- }
- public static HttpContext HttpContext
- {
- get
- {
- HttpContext context = HttpContext.Current;
- if (context == null)
- {
- HttpRequest request = new HttpRequest("Default.aspx", "http://weixin.senparc.com/default.aspx", null);
- StringWriter sw = new StringWriter();
- HttpResponse response = new HttpResponse(sw);
- context = new HttpContext(request, response);
- }
- return context;
- }
- }
- }
- }
|