global-asax

How to catch HttpRequestValidationException in production

佐手、 提交于 2019-12-18 02:18:12
问题 I have this piece of code to handle the HttpRequestValidationException in my global.asax.cs file. protected void Application_Error(object sender, EventArgs e) { var context = HttpContext.Current; var exception = context.Server.GetLastError(); if (exception is HttpRequestValidationException) { Response.Clear(); Response.StatusCode = 200; Response.Write(@"<html><head></head><body>hello</body></html>"); Response.End(); return; } } If I debug my webapplication, it works perfect. But when i put it

Global.asax is not publishing and event are not firing in Global.asax

一世执手 提交于 2019-12-17 20:27:32
问题 I am developing ASP.NET web application and for unhandled exception i am making use of Global.asax file Where I wrote a logic to write the error logs as Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) 'Code that runs when an unhandled error occurs End Sub It all works locally but when published the website global.asax not being published still i uploaded global.asax to remote server but events are not firing My application uses IIS 7 as a Web server Do i need any sort of

global.asax works on local computer but not after i publish to server

旧时模样 提交于 2019-12-17 16:35:44
问题 How can I get my global.asax file to publish to our ftp site? I have added a global.asax file to my project (using asp.net with c# from vs2010) which works great on my local machine. Then when I publish to our ftp site. Then copy from the ftp folder into the site folder overwriting old files. It doesn't work. I am using Windows Server 2008 R2 Enterprise. 回答1: Check that the "Build action" of the Global.asax file is set to "Content" in the file properties. All files set to content will be

“HttpContext.Current.Session” vs Global.asax “this.Session”

蓝咒 提交于 2019-12-17 10:52:08
问题 Recently, while working on some code for an ASP.NET project at work. We needed a tracking util to take basic metrics on user activity (page hit count etc) we would track them in Session, then save the data to DB via Session_End in Global.asax. I began hacking away, the initial code worked fine, updating the DB on each page load. I wanted to remove this DB hit on each request though and just rely on Session_End to store all the data. All of the tracking code is encapsulated in the Tracker

“HttpContext.Current.Session” vs Global.asax “this.Session”

我只是一个虾纸丫 提交于 2019-12-17 10:51:16
问题 Recently, while working on some code for an ASP.NET project at work. We needed a tracking util to take basic metrics on user activity (page hit count etc) we would track them in Session, then save the data to DB via Session_End in Global.asax. I began hacking away, the initial code worked fine, updating the DB on each page load. I wanted to remove this DB hit on each request though and just rely on Session_End to store all the data. All of the tracking code is encapsulated in the Tracker

ASP.NET MVC app custom error pages not displaying in shared hosting environment

廉价感情. 提交于 2019-12-17 10:32:41
问题 I'm having an issue with custom errors on an ASP.NET MVC app I've deployed on my shared host. I've created an ErrorController and added the following code to Global.asax to catch unhandled exceptions, log them, and then transfer control to the ErrorController to display custom errors. This code is taken from here: protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Clear(); HttpException httpEx = ex as HttpException; RouteData

How to handle session end in global.asax?

谁说胖子不能爱 提交于 2019-12-17 03:18:56
问题 I'm working in chat application, I used HashTable for containing User and Operator as a Key & Object of ChatRoom Class as a value of HashTable. Main problem is that When user or Operator close browser or disconnected without logout then It is automatically logout on the end of the session. Please help me related to that and how to use Global.asax in this matter. 回答1: You can use global.asax's session end event to remove the unexpectedly disconnected user : void Session_End(Object sender,

Multiple HttpPost method in Web API controller

冷暖自知 提交于 2019-12-16 23:43:08
问题 I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following: Controller public class VTRoutingController : ApiController { [HttpPost] public MyResult Route(MyRequestTemplate routingRequestTemplate) { return null; } [HttpPost] public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate) { return null; } } Here MyRequestTemplate represents the template class responsible for handling the Json coming through the

When does HttpRequest get created?

 ̄綄美尐妖づ 提交于 2019-12-14 03:54:35
问题 In my MVC web application, I'm checking Request.IsLocal to see if the application is running on my machine--if it is, I set a Global static variable which tells the rest of my application that I am in 'Debug Mode'. The problem is, I don't know when to do this check. I tried to do it in the global.asax.cs file, under Application_Start(), like this: protected void Application_Start() { if (Request.IsLocal) isDebug = true; AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes);

Global.asax template not available in Visual Studio

大兔子大兔子 提交于 2019-12-13 15:17:44
问题 When I attempt to "add new item" to my web project (by right-clicking, add new item) - there is no template for it. What might the problem be? I'm using VS2008. Additional Info: When I right click on the solution and "Add", "New Web Site" - I have zero tempates to choose from. I have tried running devenv /installvstemplates and this template box is still empty. I have only three templates in the following directory. Is there somewhere I can just copy the other templates from manually? C: