Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用global.asax中的应用程序启动事件处理程序显示欢迎消息_C#_Asp.net - Fatal编程技术网

C# 使用global.asax中的应用程序启动事件处理程序显示欢迎消息

C# 使用global.asax中的应用程序启动事件处理程序显示欢迎消息,c#,asp.net,C#,Asp.net,我只是想在应用程序启动时弹出一条消息。我试过这个,但不起作用 <%@ Application Language="C#" %> <script Language="C#" runat="server"> void Application_Start(object sender, EventArgs e) { // Code that runs on application startup

我只是想在应用程序启动时弹出一条消息。我试过这个,但不起作用

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

    <script Language="C#" runat="server">

      void Application_Start(object sender, EventArgs e) 
        {
            // Code that runs on application startup
            HttpContext.Current.Response.Write("<hr/>Welcome to our final project this is an example of an event handler");

        }

无效应用程序\u启动(对象发送方,事件参数e)
{
//在应用程序启动时运行的代码
HttpContext.Current.Response.Write(“
欢迎来到我们的最终项目,这是一个事件处理程序的示例”); }

它不会返回错误,但也不会显示我编写的消息,是否仍要使用
MessageBox.show
或类似的方法来完成此操作

我实现这一目标的方法是:

在我的Global.asax文件中,我声明了一个session start变量,并将其设置为App变量,如下所示

void Session_Start(object sender, EventArgs e)
    {
        var counter = 1;
        HttpContext.Current.Application["Counter"] = counter;
    }
@if (App.Counter == 1){<text>onload="modal()"</text>; App.SessionStart = 2;}
在default.aspx文件中,我有一个用于正文的onload()函数,该函数将在App.Counter=1时显示消息的模态,然后将其更改为2,如下所示

void Session_Start(object sender, EventArgs e)
    {
        var counter = 1;
        HttpContext.Current.Application["Counter"] = counter;
    }
@if (App.Counter == 1){<text>onload="modal()"</text>; App.SessionStart = 2;}
@if(App.Counter==1){onload=“modal()”;App.SessionStart=2;}
或者,您可以使用onload函数,而不是onload函数

@if (App.Counter == 1){
    <p>Your welcome message here!</p>
    App.SessionStart = 2;
}
@if(App.Counter==1){
欢迎留言

App.SessionStart=2; }
您希望消息出现在哪里?此代码在服务器上运行,没有可显示的窗口。仅供参考,
Application\u Start
不会在每个用户第一次访问应用程序时触发。它在任何用户第一次访问应用程序时触发。只有一次。@johnsa了解如何使它显示在页面中,或者更好地使它成为一个弹出对话框,显示我的消息。您不能。您必须在web应用程序中这样做。最可能的情况是,您希望使用表单身份验证,并且当用户未登录时,您希望将他们引导到登录页面。一旦他们登录,您可能希望在主页上或其他地方显示消息。我怀疑您对web开发了解不多。@johnSaunders不,这些事件处理程序对我来说是全新的。但谢谢你我会想办法的out@johnSaunders想出了一个办法,让这项工作使用您的意见作为指导谢谢!