简体   繁体   English

如何访问global.asax中的javascript变量?

[英]how to access javascript variable in global.asax?

I have a javascript variable in a page default.aspx 我在页面default.aspx中有一个javascript变量

var name="user1"

window.location="test.aspx"

this page will submit to test.aspx and in global.asax while firing Application_BeginRequest event ,i need to access the variable "name". 在激活Application_BeginRequest事件时,此页面将提交到test.aspx并在global.asax中,我需要访问变量“name”。 i need to do this without cookies. 我需要在没有cookie的情况下这样做。 Anyone can help me on this? 有人可以帮我吗?

var name="user1" is a javascript variable that you could access inside Application_BeginRequest from the Request object assuming you have passed it to the test.aspx page when redirecting: var name="user1"是一个javascript变量,您可以从Request对象中访问Application_BeginRequest ,假设您在重定向时将其传递给test.aspx页面:

var name = "user1";
window.location.href = 'test.aspx?name=' + encodeURIComponent(name);

and then: 接着:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    string name = HttpContext.Current.Request["name"];
    if (!string.IsNullOrEmpty(name))
    {
        // the name variable was present in the request => do something with it
    }
}

If by "submit" you mean perform a POST or GET request then you'll need to pass name as a url-encoded string to the server as a form POST or as a querystring parameter in a GET request. 如果通过“提交”表示执行POSTGET请求,则需要将name作为url-encoded字符串作为表单POST或作为GET请求中的查询字符串参数传递给服务器。

Then, in the Application_BeginRequest access the Request from the Current HttpContext 然后,在Application_BeginRequestCurrent HttpContext访问Request

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM