URGENT:当从资源文件中提取aspx文件时,window.open不呈现服务器端代码 [英] URGENT: window.open does not render server-side code when aspx file pulled from a resource file

查看:50
本文介绍了URGENT:当从资源文件中提取aspx文件时,window.open不呈现服务器端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的情况:


我有一个存储在资源文件中的aspx文件。所有C#代码都是通过< script runat =" server"标记内联写入的
。我们叫这个页面

B.我还有一个页面A,其中包含一些调用

window.open的javascript代码。我将页面B的资源URL传递到Page A的window.open

调用。然后加载并执行页面B,但不呈现服务器端的

代码。如果我查看页面的来源,代码(和页面

声明)是可见的。


如何正确呈现C#代码?

示例代码:


Assembly.cs

[assembly:WebResourceAttribute(" MyTest.MyFile.aspx",") ; text / html",

PerformSubstitution = true)]

PageA.aspx(C#)

公共字符串ns ="" ;;


protected void Page_Load(object sender,EventArgs e)

{

ns = Page.ClientScript.GetWebResourceUrl(GetType() ,

" MyTest.MyFile.aspx");


}


PageA.aspx(javascript)

<%@ Page Language =" C#" AutoEventWireup =" true"
CodeFile =" Default2.aspx.cs"继承= QUOT;缺省2" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns = QUOT; HTTP://www.w3.org/1999/xhtml" >

< head runat =" server">

< title> Untitled Page< / title>

< script语言= QUOT; JavaScript的" type =" text / javascript">

<! -


函数Button1_onclick()

{

window.open(<%= ns%>," _blank",

" menubar = no,titlebar = no,toolbar = no,status = no" );

}

// - >

< / script>

< / head> ;

< body>

< input id =" Button1"类型= QUOT按钮" value =" button"

language =" javascript" onclick =" return Button1_onclick()" />

< / body>

< / html>


MyFile.ascx(存储在资源文件中)

<%@ Page Language =" C#" %>


< html>

< head runat =" server">

< title> MyTitle< / title>

< / head>

< body bgcolor ="#6699cc">

< form id = QUOT; form1的" runat =" server">

< / form>

< / body>


< / html> ;


< script runat =" server" type =" text / C#">


protected override void OnLoad(EventArgs e)

{

Response.Write (我写信给dee页面!;

base.OnLoad(e);

}

< / script> ;

Here is my situation:

I have an aspx file stored in a resource file. All of the C# code is
written inline via <script runat="server"tags. Let''s call this page
B. I also have page A that contains some javascript code that calls
window.open. I pass the resource url of page B to Page A''s window.open
call. Page B is then loaded and executed but none of the server-side
code is rendered. If I view the source of the page, the code (and page
declaration) are visible.

How do I get this to render the C# code properly?
Sample code:

Assembly.cs
[assembly: WebResourceAttribute("MyTest.MyFile.aspx", "text/html",
PerformSubstitution = true)]
PageA.aspx (C#)
public string ns = "";

protected void Page_Load(object sender, EventArgs e)
{
ns = Page.ClientScript.GetWebResourceUrl(GetType(),
"MyTest.MyFile.aspx");

}

PageA.aspx (javascript)
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--

function Button1_onclick()
{
window.open(<%=ns%>, "_blank",
"menubar=no,titlebar=no,toolbar=no,status=no") ;
}
// -->
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
language="javascript" onclick="return Button1_onclick()" />
</body>
</html>

MyFile.ascx (stored in resource file)
<%@ Page Language="C#" %>

<html>
<head runat="server">
<title>MyTitle</title>
</head>
<body bgcolor="#6699cc">
<form id="form1" runat="server">
</form>
</body>

</html>

<script runat="server" type="text/C#">

protected override void OnLoad(EventArgs e)
{
Response.Write("I am writing to dee page!");
base.OnLoad(e);
}
</script>

推荐答案

嗨鲍勃,


你试过通过输入它来打开Page B.网址是什么?无论您是使用JavaScript还是以任何其他方式打开页面,服务器都没有任何区别。我想你的页面根本不起作用。您是否使用ASP.NET认可的任何文件扩展名为您的页面?


HTH,

Axel Dahmen


-----------------

" Bob Jones" < go ******** @ gmail.comschrieb im Newsbeitrag新闻:11 ********************** @ v33g2000cwv.googlegr psps.com。 ..
Hi Bob,

have you tried opening Page B by entering its URL? It doesn''t make any difference for the server whether you open a page using JavaScript or any other way. I guess your page doesn''t work at all. Did you use any of the file extensions recognized by ASP.NET for your page?

HTH,
Axel Dahmen

-----------------
"Bob Jones" <go********@gmail.comschrieb im Newsbeitrag news:11**********************@v33g2000cwv.googlegr oups.com...

这是我的情况:


我有一个存储在资源文件中的aspx文件。所有C#代码都是通过< script runat =" server"标记内联写入的
。我们叫这个页面

B.我还有一个页面A,其中包含一些调用

window.open的javascript代码。我将页面B的资源URL传递到Page A的window.open

调用。然后加载并执行页面B,但不呈现服务器端的

代码。如果我查看页面的来源,代码(和页面

声明)是可见的。


如何正确呈现C#代码?

示例代码:


Assembly.cs

[assembly:WebResourceAttribute(" MyTest.MyFile.aspx",") ; text / html",

PerformSubstitution = true)]

PageA.aspx(C#)

公共字符串ns ="" ;;


protected void Page_Load(object sender,EventArgs e)

{

ns = Page.ClientScript.GetWebResourceUrl(GetType() ,

" MyTest.MyFile.aspx");


}


PageA.aspx(javascript)

<%@ Page Language =" C#" AutoEventWireup =" true"
CodeFile =" Default2.aspx.cs"继承= QUOT;缺省2" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns = QUOT; HTTP://www.w3.org/1999/xhtml" >

< head runat =" server">

< title> Untitled Page< / title>

< script语言= QUOT; JavaScript的" type =" text / javascript">

<! -


函数Button1_onclick()

{

window.open(<%= ns%>," _blank",

" menubar = no,titlebar = no,toolbar = no,status = no" );

}

// - >

< / script>

< / head> ;

< body>

< input id =" Button1"类型= QUOT按钮" value =" button"

language =" javascript" onclick =" return Button1_onclick()" />

< / body>

< / html>


MyFile.ascx(存储在资源文件中)

<%@ Page Language =" C#" %>


< html>

< head runat =" server">

< title> MyTitle< / title>

< / head>

< body bgcolor ="#6699cc">

< form id = QUOT; form1的" runat =" server">

< / form>

< / body>


< / html> ;


< script runat =" server" type =" text / C#">


protected override void OnLoad(EventArgs e)

{

Response.Write (我写信给dee页面!;

base.OnLoad(e);

}

< / script> ;
Here is my situation:

I have an aspx file stored in a resource file. All of the C# code is
written inline via <script runat="server"tags. Let''s call this page
B. I also have page A that contains some javascript code that calls
window.open. I pass the resource url of page B to Page A''s window.open
call. Page B is then loaded and executed but none of the server-side
code is rendered. If I view the source of the page, the code (and page
declaration) are visible.

How do I get this to render the C# code properly?
Sample code:

Assembly.cs
[assembly: WebResourceAttribute("MyTest.MyFile.aspx", "text/html",
PerformSubstitution = true)]
PageA.aspx (C#)
public string ns = "";

protected void Page_Load(object sender, EventArgs e)
{
ns = Page.ClientScript.GetWebResourceUrl(GetType(),
"MyTest.MyFile.aspx");

}

PageA.aspx (javascript)
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--

function Button1_onclick()
{
window.open(<%=ns%>, "_blank",
"menubar=no,titlebar=no,toolbar=no,status=no") ;
}
// -->
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
language="javascript" onclick="return Button1_onclick()" />
</body>
</html>

MyFile.ascx (stored in resource file)
<%@ Page Language="C#" %>

<html>
<head runat="server">
<title>MyTitle</title>
</head>
<body bgcolor="#6699cc">
<form id="form1" runat="server">
</form>
</body>

</html>

<script runat="server" type="text/C#">

protected override void OnLoad(EventArgs e)
{
Response.Write("I am writing to dee page!");
base.OnLoad(e);
}
</script>


2月20日上午9:13,Axel Dahmen < KeenToK ... @ newsgroup.nospamwrote:
On Feb 20, 9:13 am, "Axel Dahmen" <KeenToK...@newsgroup.nospamwrote:

嗨Bob,


您是否尝试通过输入打开Page B它的URL?无论您是使用JavaScript还是以任何其他方式打开页面,服务器都没有任何区别。我想你的页面根本不起作用。您是否使用ASP.NET认可的任何文件扩展名为您的页面?


HTH,

Axel Dahmen


-----------------

" Bob Jones" < goodold ... @ gmail.comschrieb im Newsbeitragnews:11 ********************** @ v33g2000c wv.googlegroups.com ...
Hi Bob,

have you tried opening Page B by entering its URL? It doesn''t make any difference for the server whether you open a page using JavaScript or any other way. I guess your page doesn''t work at all. Did you use any of the file extensions recognized by ASP.NET for your page?

HTH,
Axel Dahmen

-----------------
"Bob Jones" <goodold...@gmail.comschrieb im Newsbeitragnews:11**********************@v33g2000c wv.googlegroups.com...

这是我的情况:
Here is my situation:


我有一个存储在资源文件中的aspx文件。所有C#代码都是通过< script runat =" server"标记内联写入的
。我们叫这个页面

B.我还有一个页面A,其中包含一些调用

window.open的javascript代码。我将页面B的资源URL传递到Page A的window.open

调用。然后加载并执行页面B,但不呈现服务器端的

代码。如果我查看页面的来源,则可以看到代码(和页面

声明)。
I have an aspx file stored in a resource file. All of the C# code is
written inline via <script runat="server"tags. Let''s call this page
B. I also have page A that contains some javascript code that calls
window.open. I pass the resource url of page B to Page A''s window.open
call. Page B is then loaded and executed but none of the server-side
code is rendered. If I view the source of the page, the code (and page
declaration) are visible.


如何正确呈现C#代码?
How do I get this to render the C# code properly?


示例代码:
Sample code:


Assembly.cs

[assembly:WebResourceAttribute(" MyTest.MyFile.aspx"," text / html",

PerformSubstitution = true)]
Assembly.cs
[assembly: WebResourceAttribute("MyTest.MyFile.aspx", "text/html",
PerformSubstitution = true)]


PageA.aspx(C#)

公共字符串ns ="" ;;
PageA.aspx (C#)
public string ns = "";


protected void Page_Load(object sender,EventArgs e)

{

ns = Page .ClientScript.GetWebResourceUrl(GetType(),

" MyTest.MyFile.aspx");
protected void Page_Load(object sender, EventArgs e)
{
ns = Page.ClientScript.GetWebResourceUrl(GetType(),
"MyTest.MyFile.aspx");


}
}


PageA.aspx(javascript)

<%@ Page Language =" C#" AutoEventWireup =" true"
CodeFile =" Default2.aspx.cs"继承= QUOT;缺省2" %GT;
PageA.aspx (javascript)
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns =" http://www.w3.org/1999/xhtml" >

< head runat =" server">

< title> Untitled Page< / title>

< script语言= QUOT; JavaScript的" type =" text / javascript">

<! -
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--


function Button1_onclick()

{

window.open(<%= ns%>," _blank",

" menubar = no,titlebar = no, toolbar = no,status = no");

}
function Button1_onclick()
{
window.open(<%=ns%>, "_blank",
"menubar=no,titlebar=no,toolbar=no,status=no") ;
}


// - >

< / script>

< / head>

< body>

< input id =" Button1"类型= QUOT按钮" value =" button"

language =" javascript" onclick =" return Button1_onclick()" />

< / body>

< / html>
// -->
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
language="javascript" onclick="return Button1_onclick()" />
</body>
</html>


MyFile.ascx(存储在资源文件中)

<%@ Page Language =" C#" %GT;
MyFile.ascx (stored in resource file)
<%@ Page Language="C#" %>


< html>

< head runat =" server">

< title> MyTitle< / title>

< / head>

< body bgcolor ="#6699cc">

< form id =" form1" runat =" server">

< / form>

< / body>
<html>
<head runat="server">
<title>MyTitle</title>
</head>
<body bgcolor="#6699cc">
<form id="form1" runat="server">
</form>
</body>


< / html>
</html>


< script runat =" server"类型= QUOT;文本/ C#">
<script runat="server" type="text/C#">


protected override void OnLoad(EventArgs e)

{

Response.Write(" ;我写信给dee页面!");

base.OnLoad(e);

}

< / script> - 隐藏引用的文字 -
protected override void OnLoad(EventArgs e)
{
Response.Write("I am writing to dee page!");
base.OnLoad(e);
}
</script>- Hide quoted text -



- 显示引用的文字 -


- Show quoted text -



Axel,

直接调用页面会产生相同的输出。我不确定我是什么?b $ b了解如何将.aspx扩展名添加到

资源网址,如下所示:
HTTP://本地主机:1169 / WebResource.ax ... 75600008593750


然而,我认为你可能会做些什么。作为旁注,如果您查看页面的来源,您将看到确切的是在MyFile.ascx下指定的

(逐字)(存储在资源文件中)第一节

贴eairler。


-David


Axel,

Calling the page directly produces the same output. I am not sure I am
understanding how I would go about addid the .aspx extention to the
resource url as it looks like this:
http://localhost:1169/WebResource.ax...75600008593750

I do, however, think you may be on to something. As a side note, if
you view the source of the page you will see exactly was is specified
(verbatim) under the MyFile.ascx (stored in resource file) section I
posted eairler.

-David


看起来像我将ASPX页面的全部内容存储在一个

资源中?它是否正确 ?一个资源只存储一些数据,所以ASP.NET

引擎并不知道这实际上是你想要的东西

来运行(我是惊讶甚至它让你服务resx文件)。


我不确定总体目标是什么,但想到的第一个想法

会像往常一样将其保存在ASPX文件中。另外,详细说明你想要做什么,以防万一有人会采用更简单的方法来建议...

Bob Jones < go ******** @gmail.comaécritdansle message de news:
11 ******** @ v33g2000cwv.googlegroups。 com ...
It looks like to me the whole content of an ASPX page is stored inside a
resource ? Is this correct ? A resource just stores some data so the ASP.NET
engine doesn''t have any idea that this is actually something you would like
to run (I''m surprised even it lets you serve resx files).

I''m not sure what is the overall goal but the first idea that comes to mind
would be to save this in an ASPX file as usual. Else elaborate on what you
are trying to do in case someone would have a simpler approach to suggest...
"Bob Jones" <go********@gmail.coma écrit dans le message de news:
11**********************@v33g2000cwv.googlegroups. com...

这是我的情况:


我有一个存储在资源中的aspx文件文件。所有C#代码都是通过< script runat =" server"标记内联写入的
。我们叫这个页面

B.我还有一个页面A,其中包含一些调用

window.open的javascript代码。我将页面B的资源URL传递到Page A的window.open

调用。然后加载并执行页面B,但不呈现服务器端的

代码。如果我查看页面的来源,代码(和页面

声明)是可见的。


如何正确呈现C#代码?


示例代码:


Assembly.cs

[assembly:WebResourceAttribute(" MyTest.MyFile。 aspx"," text / html",

PerformSubstitution = true)]


PageA.aspx(C#)

public string ns ="";


protected void Page_Load(object sender,EventArgs e)

{

ns = Page .ClientScript.GetWebResourceUrl(GetType(),

" MyTest.MyFile.aspx");


}


PageA.aspx(javascript)

<%@ Page Language =" C#" AutoEventWireup =" true"
CodeFile =" Default2.aspx.cs"继承= QUOT;缺省2" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns = QUOT; HTTP://www.w3.org/1999/xhtml" >

< head runat =" server">

< title> Untitled Page< / title>

< script语言= QUOT; JavaScript的" type =" text / javascript">

<! -


函数Button1_onclick()

{

window.open(<%= ns%>," _blank",

" menubar = no,titlebar = no,toolbar = no,status = no" );

}


// - >

< / script>

< / head>

< body>

< input id =" Button1"类型= QUOT按钮" value =" button"

language =" javascript" onclick =" return Button1_onclick()" />

< / body>

< / html>



MyFile.ascx(已存储)在资源文件中)

<%@ Page Language =" C#" %>


< html>

< head runat =" server">

< title> MyTitle< / title>

< / head>

< body bgcolor ="#6699cc">

< form id = QUOT; form1的" runat =" server">

< / form>

< / body>


< / html> ;


< script runat =" server" type =" text / C#">


protected override void OnLoad(EventArgs e)

{

Response.Write (我写信给dee页面!;

base.OnLoad(e);

}

< / script> ;
Here is my situation:

I have an aspx file stored in a resource file. All of the C# code is
written inline via <script runat="server"tags. Let''s call this page
B. I also have page A that contains some javascript code that calls
window.open. I pass the resource url of page B to Page A''s window.open
call. Page B is then loaded and executed but none of the server-side
code is rendered. If I view the source of the page, the code (and page
declaration) are visible.

How do I get this to render the C# code properly?
Sample code:

Assembly.cs
[assembly: WebResourceAttribute("MyTest.MyFile.aspx", "text/html",
PerformSubstitution = true)]
PageA.aspx (C#)
public string ns = "";

protected void Page_Load(object sender, EventArgs e)
{
ns = Page.ClientScript.GetWebResourceUrl(GetType(),
"MyTest.MyFile.aspx");

}

PageA.aspx (javascript)
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--

function Button1_onclick()
{
window.open(<%=ns%>, "_blank",
"menubar=no,titlebar=no,toolbar=no,status=no") ;
}
// -->
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
language="javascript" onclick="return Button1_onclick()" />
</body>
</html>

MyFile.ascx (stored in resource file)
<%@ Page Language="C#" %>

<html>
<head runat="server">
<title>MyTitle</title>
</head>
<body bgcolor="#6699cc">
<form id="form1" runat="server">
</form>
</body>

</html>

<script runat="server" type="text/C#">

protected override void OnLoad(EventArgs e)
{
Response.Write("I am writing to dee page!");
base.OnLoad(e);
}
</script>



这篇关于URGENT:当从资源文件中提取aspx文件时,window.open不呈现服务器端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆