.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Global.asax Mail issue

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

Hi All

i am having a problem with mail message .which is being run from global.asax page.

means i have set some time span for mail-message code to run.All the clients of the comp should get the renewal alert mail as per their package expires.my code works fine in my project.nut when i publish the code and upload to the server mail does seem to work.

some times the same issue with local also. here is the sample code.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
       'Code that runs on application startup        
       myTimer.Interval = timeInterval
       myTimer.AutoReset = True
       AddHandler myTimer.Elapsed, AddressOf myTimer_Elapsed
       myTimer.Enabled = True
   End Sub

Inside myTimer.Elapsed

View Complete Post

More Related Resource Links

Quick Error messages with Global.asax

The article Quick Error messages with Global.asax was added by lykasd on Wednesday, August 11, 2010.

Error pages without any effort void Application_Error(object sender, EventArgs e) { Server.Transfer("/error.aspx"); //Displays the error page } In error.aspx add this to the content area. p>We're sorry, but the %=Server.GetLastError

Windows 7, IIS 7.5 and VS2010: can't edit global.asax


Hey and thanks!


As the subject line notes the software in use, anyone have an idea why I can't edit global.asax in VS2010 (being ran with the 'run as administrator' advanced property check box checked)?  The file properties in explorer show local machine admins have full control (I am in that category) and also that IIS has windows auth enabled for the default web site.  What is this other level of security on here that I'm missing?  I can edit web.config, vb files and general aspx files with no problem--just the global.asax file causing a headache...





system.net.mail cc issue


I have an array of addresses.....

	Protected Function GetData() As String()
Dim stringArr(3) As String

stringArr(0) = "youremail1@fakeaddress.com"
stringArr(1) = "youremail2@fakeaddress.com"
stringArr(2) = "youremail3@fakeaddress.com"

Return stringArr

End Function

I am getting an error when i run the code in the CC part....please put this in the right syntax..

MassMail.CC.Add() .......getdata???

I have a problem Global.asax

Master  Desing        <head runat="server"><title><asp:ContentPlaceHolder ID="TitleContent" runat="server" />    </title>    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />    <link href="../../Content/menu/chromestyle2.css" rel="stylesheet" type="text/css" />    <script src="../../Scripts/menu/chrome.js" type="text/javascript"></script></head>   Global.asax  //Routes Event Catagory  routes.MapRoute("eventCatagory", "Catagory/{catagoriesID}/{catagories}",                                 new { controller = "Catagory", action = "Catagory", catagories = "", catagoriesID = UrlParameter.Optional }); //Routes Event Catagory Detailroutes.MapRoute("eventCatagoryDetail", "Catagory/{subCatagoryID}/{subCatagoryname}",                        &n

Using Global.asax to Set Session Variables Pulled From SQLServer

I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class. 

Function in Global.asax is not running

Hi, I am using a Global.asax in on my webpage to run a function with an interval. In this test I have set the interval to 1 minute to be able to see what happens. I have declared a timer in the Application Start which should mean that when I open up the webpage after I have uploaded the Global.asax the timer will start.   However with this code below where I try to create a file named newFile.txt, this file is not created. I cant really understand what I could be missing. It seems that the function is not running ?<%@ Application Language="C#" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Collections.Generic" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Net.Mail" %> <%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.Threading" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Text" %> <%@ Import Namespace="Microsoft.Win32" %> <%@ Import Namespace="System.Reflection" %> <%@ Impo

Global.asax Application_BeginRequest

When I was in the link page is a link to the site all the program, Application_BeginRequest event in Global.asax is triggered, But my link is a link to an external time will not trigger this event, and I ask when my link is connected to an external URL, How to trigger Application_BeginRequest event Thank you.   Such as web link in the URL if connected to yahoo, I take it lead to another page.  Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) Dim originalPath As String = HttpContext.Current.Request.Url.Host.ToLower() If originalPath.Contains("yahoo") Then Context.Response.Redirect("StopUrl.aspx") End If End Sub  

Application level event without global.asax

I have a need to add an application level event (like Application_Start) but not in global.asax.  The reason that I can't use global.asax is because this is a web application for which I don't have source code but I want to add some functionality to it.  I need to insert an application start code and was wondering it there was anyway to do it.  I'm not sure that if I add a class or aspx page to the sie if it will dynamically compile since this is a web application.  I know this is a crazy request but let me know what you think.Also, this web site was written in .NET 2.0.Thanks.

Passing data to a Controller from global.asax


Hello all! I'm in a situation where I need to pass some information (state) to a base controller from which all of my controllers derive. In my global.asax, I'm calling a web service to get some state about the user. This state applies to every page in my web app, so the base controller needs to know about it. The state consists of about 4 fields. Is there a standard way to do this? 

I'm using ASP.NET MVC 2.

Thanks in advance for your time!


Empty Catch in Global.asax to prevent exception from stopping a web application?



I'm using a static Timer in my Global.asax to run a method at regular intervals. When the method throws an exception, my application is stopped. I have used an empty catch to prevent exceptions from stopping the application something like below code. Is there a disadvantage to use such an approach?


 protected void Application_Start(object sender, EventArgs e)

 public class TimerStarter
            private static System.Threading.Timer threadingTimer;

            public static void StartTimer()
                if (null == threadingTimer)
                    threadingTimer = new System.Threading.Timer(new System.Threading.TimerCallback(CheckData),HttpContext.Current, 0, 50000);

            private static void CheckData(object sender)
                   // a method that reading xml file from another url              
                    // empty catch to prevent stopping the application




client side Print issue in Asp.net application when we hosted in webserver(Global, shaired space).


I have an asp.net application . I hosted this application in shaired server. When the client is logined this site , they have an option for print the certificate based up on the number of copies.  My questin is right now i generated this one pdf, so pdf it self i can print unlimited copies. So i want to restrict this one by blocking the print dialogbox. I want to print it based up on the number of copies from databsase of a table value.  then how to identify the clint side printer to print this one.

Please give any suitable solution for it to print the number of copies without popup the print dialogshop.


So please give a goodd solution for it to print the certificaate in client side based up on the number of copies from database and should be restrict print dialogbox .


Requirments is

 Any methord print client side print based up on the number of copies from database and restrict print dialogbox . User should not be prin number of copiest apart from the number of copies from database.


Please give me the tips for impliment it. and send me source code for easy understanding


Thank You.........

Session end and global.asax



I'm wondering if ther's a simple way of achieving the following.

When a new session starts, I create some cookies and session objects from global.asax session start.

If a user logs out, I want to abandon the session - I presume using session.abandon, and i also want to clear the cookies.  They are set to expire after the session ends (no expiry date).  This may be an automatic thing, but I've not tested as yet.

When a user logs back in again I want to recreate those objects - in other words, kick off global.asax again.  Is that what happens or do I need to recreate manually?



Exception handling in Global.asax of ASP.net


I want to handle exceptions in my applications in Global.asax and transfer the exception to my custom error page, so that is in a central place. I want to take this exception object into my oopserror.aspx page and format it and display a custom message. i tried to use GetLastError() in my oopsError.aspx page, but my exception object was always null. Following is the code snippet that i'm using and i'm getting exception.

void Application_Error(object sender, EventArgs e)
   // Code that runs when an unhandled error occurs
   Exception exception;
   exception = Server.GetLastError();

   Session.Add("Exception", exception);


Following is the exception when the above code is executed.

{"Session state is not available in this context."}
   at System.Web.HttpApplication.get_Session()
   at UserInterface.Global.Application_Error(Object sender, EventArgs e) in C:\UserInterface\Global.asax.cs:line 51
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Web.HttpApplication.RaiseOnError()

Is there a way that i can securly take my session object from global.asax to my oopserror.aspx? Any ideas?

System.Net.Mail Header issue


I am trying to send additional info from a form via the Headers property of mail.  When I run the below code, the email is sent along with the From, To, Subject and Bosy values, but nothing else.  How do I add the values listed?


Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim mm As New MailMessage()

mm.From = New MailAddress(txtEmail.text)

mm.To.Add(New MailAddress("example@yahoo.com"))

'(2) Assign the MailMessage's properties

mm.Subject = "Get A Quote"

mm.Body = "This is a test."

mm.Headers.Add ("X-ContractorName",txtContractor.text)

mm.Headers.Add ("X-FirstName",txtFirstName.text)

mm.Headers.Add ("X-LastName",txtLastName.text)

mm.Headers.Add ("X-Address",txtAddress.text)

mm.Headers.Add ("X-City",txtCity.text)

mm.Headers.Add ("X-State",txtState.text)

mm.Headers.Add ("X-Zip",txtZip.text)

mm.Headers.Add ("X-MainPhone",txtMainPhone.text)

mm.Headers.Add ("X-AlternatePhone",txtAlternatePhone.text)

mm.Headers.Add ("X-Email",txtEmail.text)

mm.Headers.Add ("X-ContainerSize",containerSize.text)

mm.Headers.Add ("X-ContainerContentOther",text

Global.asax file in WCF for different end points


Global.asax is available in asp.net application. But when I added WCF application i couldn’t find the file. I saw read in one of the questions that global.asax cannot be used for tcp endpoints.

I’m trying to use application_error method in global.asax and catch all the exceptions in this method.


How can I use global.asax with http and tcp endpoint? Or is there any other way to implement this?


PostBack triggers Session_Start on Global.asax


Hi all, I'm facing a strange issue.

I have a simple aspx Page, which html contains:

<asp:Button ID="btn1" runat="server" Text="Set Session" onclick="btn1_Click" /> 
<asp:Button ID="btn2" runat="server" Text="Get Session" onclick="btn2_Click" />

and code behind:

public partial class MyPage : System.Web.UI.UserControl
    private List<string> myElements
        get { return (List<string>)Session["elements"]; }
        set { Session["elements"] = value; }

    protected void Page_Load(object sender, EventArgs e)


    protected void btn1_Click(object sender, EventArgs e)
        List<string> strs = new List<string>();

        myElements = strs;

    protected void btn2_Click(object sender, EventArgs e)
        List<string> strs = myElements;

        if (strs != null && strs.Count > 0)
            string s = "Ok";


This is quite simple. When I press btn1, it sets correctly the Session Key

Session and global asax


i use session state for logged in  users
if session lost(finished) for user and i use this session to insert as a forien key in a table
this will generate runtime error as this id become equal to zero
how can i develop a method to log out the user automatically when session timeout reached
inseted to check at every button on the velue of session.
i have ideia to check on session on global file in Application_BeginRequest event

but give me error
what do you think of this method???

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend