如何使用Global.asax [英] How to use the Global.asax

查看:177
本文介绍了如何使用Global.asax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net的初学者,所以请用简单的方式指导我。我想了解在网站或Web应用程序中使用global.asax。在哪种情况下有必要使用?

i am beginner in asp.net so kindly guide me in simple and to the point wording. i want to understand the use of global.asax in a website or web application. in which situations it is necessary to use?

推荐答案

查看此

http://www.dotnetperls.com/global-asax [ ^ ]


您可以在不同的注意事项中使用Global.asax,例如Application_BeginRequest - 每当有任何请求来时到你的网站,你可以写任何常见的东西。



我遇到过的真实世界情景

我遇到过十字架使用来自html5应用程序的jQuery调用休息服务时的域问题。为了处理这个我已经在我的WCF服务应用程序的Application_BeginRequest上放了一些代码,每当我尝试调用该服务时执行。

以下是Global.asax中的方法用于不同的目的。请仔细阅读

与事件相对应的方法重新发送每个请求

Application_BeginRequest() - 在请求Web应用程序时触发。

Application_AuthenticateRequest - 在用户凭据通过身份验证之前解冻。您可以在此处指定自己的身份验证逻辑。

Application_AuthorizeRequest() - 在成功验证用户凭据时触发。您可以使用此方法向用户授予权限。

Application_ResolveRequestCache() - 成功完成授权请求后触发。

Application_AcquireRequestState() - 在为当前请求检索会话状态之前触发。

Application_PreRequestHandlerExecute() - 在页面框架开始之前触发,然后执行事件处理程序来处理请求。

Application_PostRequestHandlerExecute() - 在HTTP处理程序执行请求后触发。

Application_ReleaseRequestState() - 在会话集合中保存的当前状态数据之前触发序列化。

Application_UpdateRequestCache() - 在将信息添加到页面的输出缓存之前触发。

Application_EndRequest() - 在每个请求结束时触发

与偶数对应的方法不会在每个请求中触发的

Application_Start() - 在从Web服务器请求第一个资源时触发Web应用程序启动。

Session_Start() - 在每个请求页面的新用户启动会话时触发。

Application_Error() - 发生错误时触发。

Session_End() - 当用户的会话结束时触发。

Application_End() - 在Web应用程序结束时触发。

Application_Disposed() - 在销毁Web应用程序时触发。





希望这有帮助
You can use Global.asax in different sitautions for example Application_BeginRequest-Whenever any request come to your website you can write anything common.

Real World Scenario I have faced
I have faced cross domain issue while calling a rest service using jQuery from an html5 application.For handle this i have put some code on Application_BeginRequest of my WCF service application which Execute whenever i try to call the service.
Below are the methods in Global.asax for different purpose.Please go through for more clarity
Methods corresponding to events that fire on each request
Application_BeginRequest() – fired when a request for the web application comes in.
Application_AuthenticateRequest –fired just before the user credentials are authenticated. You can specify your own authentication logic over here.
Application_AuthorizeRequest()– fired on successful authentication of user’s credentials. You can use this method to give authorization rights to user.
Application_ResolveRequestCache() – fired on successful completion of an authorization request.
Application_AcquireRequestState() – fired just before the session state is retrieved for the current request.
Application_PreRequestHandlerExecute() - fired before the page framework begins before executing an event handler to handle the request.
Application_PostRequestHandlerExecute() – fired after HTTP handler has executed the request.
Application_ReleaseRequestState() – fired before current state data kept in the session collection is serialized.
Application_UpdateRequestCache() – fired before information is added to output cache of the page.
Application_EndRequest() – fired at the end of each request
Methods corresponding to events that do not fire on each request
Application_Start() – fired when the first resource is requested from the web server and the web application starts.
Session_Start() – fired when session starts on each new user requesting a page.
Application_Error() – fired when an error occurs.
Session_End() – fired when the session of a user ends.
Application_End() – fired when the web application ends.
Application_Disposed() - fired when the web application is destroyed.


Hope this helps


请参考以下链接我的朋友

http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx [ ^ ]



http://www.dotnetcurry.com/ShowArticle.aspx?ID=126 [ ^ ]



使用Global.asax可以实现

- > URLRewriting

- >任务计划
Refer following links my friend
http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx[^]

http://www.dotnetcurry.com/ShowArticle.aspx?ID=126[^]

Using Global.asax you can implement
->URLRewriting
->Task Scheduling


这篇关于如何使用Global.asax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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