Входные данные с (name = "amount" & amp; name = "item_name"), их значения должны быть заключены следующим образом:
value ="php code inside"
Наконец-то нашел простой ответ!
HttpRuntime.AppDomainAppVirtualPath
Доступно непосредственно при запуске приложения
Это форма /myapplication
, включающая префикс /
.
Can you use ResolveUrl("~/images/cat.jpg") to build your path?
Edit: ResolveUrl is a method of Control, not just the Page class, so you can do it this way instead (bit ugly maybe):
System.Web.UI.Control c = new Control();
String s = c.ResolveUrl(@"~/images/cat.jpg");
This is the best I came up with : Application_BeginRequest (via mark)
I use asax so rarely that I had temporarily forgotten you get different events with it. Until now I'd been creating the CSS sprites in Application_Start
. Moving it to BeginRequest was the best I could come up with.
One boolean check for every request is negligible, but would be nice if there is a different way.
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
protected void Application_BeginRequest()
{
if (!_initialized)
{
lock (thisLock)
{
_initialized = true;
GenerateCSSSprites();
}
}
}
I had this problem too when switching to IIS7 but I was able to refactor out the need for Request. Which is what this guy also suggests and provides a workaround if you can't.
Хммм ... Я не знал об изменении IIS7. Интересно, не будет ли проще отложить эту операцию, пока у вас не появится страница? Например, вы можете попытаться поместить что-то «только один раз» в Application_BeginRequest
или Session_Start
?
Или (полностью не проверено) для ловушки для отказа от подписки:
public override void Init() {
base.Init();
EventHandler handler = null;
handler = delegate {
// do stuff, once only
this.BeginRequest -= handler;
};
this.BeginRequest += handler;
}
Хитрость делать это только один раз (если одновременно поступает несколько запросов); возможно статический ctor? Например, я думаю, что это срабатывает только один раз, и только когда есть доступная страница в контексте:
static class DelayedLoader {
static DelayedLoader() {
string s = VirtualPathUtility.ToAbsolute("~/images/cat.jpg",
HttpContext.Current.Request.ApplicationPath);
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Init() { }
}
public override void Init() {
base.Init();
EventHandler handler = null;
handler = delegate {
DelayedLoader.Init();
this.BeginRequest -= handler;
};
this.BeginRequest += handler;
}