global-asax

asp.net mvc and check for if a user is logged in

无人久伴 提交于 2019-12-22 08:57:27
问题 I'm new in asp.net mvc and i need to check if a user is logged in or not in my application so i place the following piece of code in my global.asax void Application_PreRequestHandlerExecute(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; string filePath= context.Request.FilePath; string fileExtention = VirtualPathUtility.GetExtension(filePath); // to skip request for static content like (.css or .js) if

How can you hook a SharePoint 2007 feature into the Application_Start of a site?

ぃ、小莉子 提交于 2019-12-22 06:33:58
问题 I was wondering if there is a good way to hook into the Application_Start of a SharePoint 2007 site when developing a feature? I know I can directly edit the Global.asax file in the site root, but is there a way to do this so that it gets deployed with the feature? Thanks! 回答1: This is actually possible, but it doesn't involve the Global.asax file. Many of Microsoft's examples demonstrate wiring code in via the Global.asax, but this is not a best-practices approach when it comes to SharePoint

Where is global.asax.cs in Visual Studio 2010

拟墨画扇 提交于 2019-12-21 06:56:34
问题 I don't have a Global Application class code-behind any more inside my installed templates. All I have is Global.asax. I find more comfortable working with Global.asax.cs . Why am I not seeing it anymore? How to re-create Global.asax.cs? 回答1: That's because you created a Web Site instead of a Web Application. I would recommend you using a precomipled Web Application model but if you need to use a Web Site you could do the following: ~/Global.asax : <%@ Application CodeFile="Global.asax.cs"

Handling exceptions in global.asax ASP.NET MVC

孤人 提交于 2019-12-21 04:13:16
问题 I have code which is catching all exceptions in Global.asax protected void Application_Error(object sender, EventArgs e) { System.Web.HttpContext context = HttpContext.Current; System.Exception exc = context.Server.GetLastError(); var ip = context.Request.ServerVariables["REMOTE_ADDR"]; var url = context.Request.Url.ToString(); var msg = exc.Message.ToString(); var stack = exc.StackTrace.ToString(); } How I can get controller name where this error happened How I can get request client IP? And

Customised error messages are not translated in ASP.NET MVC 4

陌路散爱 提交于 2019-12-21 02:28:29
问题 I want to translate the validation message "The field Date must be a date." I've added the following keys into Application_Start() at Global.asax ClientDataTypeModelValidatorProvider.ResourceClassKey = "ModelBinders"; DefaultModelBinder.ResourceClassKey = "ModelBinders"; I've created ModelBinders.resx, ModelBinders.nl.resx, ModelBinders.fr.resx in App_GlobalResources. I've added the following string resources (or translations) in the .resx files: Name Value ==== ===== FieldMustBeDate The

Calling the Session before any Controller Action is run in MVC

天大地大妈咪最大 提交于 2019-12-20 06:29:59
问题 I have this authentication check in my global.asax file in the Session_OnStart() call: if (Session["Authenticated"] == null) { Response.Redirect("~/Login.aspx"); } This kind of session authentication is tightly coupled in all our web apps so I have to use it this way. This global.asax sits in an older Webforms project, which my MVC project is sitting in. So for this reason I believe its letting me access my controller action e.g http://localhost/controller/action directly without my session

ASP.NET: Access Session variable in global.asax

爷,独闯天下 提交于 2019-12-19 16:54:39
问题 I have an ASP.NET application and in the Global.asax ' Application Error Event, I am calling a method to trace/log the error. I want to use the session variable content here. I used the below code void Application_Error(object sender, EventArgs e) { //get reference to the source of the exception chain Exception ex = Server.GetLastError().GetBaseException(); //log the details of the exception and page state to the //Windows 2000 Event Log GUI.MailClass objMail = new GUI.MailClass(); string

Asp.net MVC Let user switch between roles

心已入冬 提交于 2019-12-19 10:19:33
问题 I'm developing a complex website with users having multiple roles. The users are also coupled on other items in the DB which, together with their roles, will define what they can see and do on the website. Now, some users have more than 1 role, but the website can only handle 1 role at a time because of the complex structure. the idea is that a user logs in and has a dropdown in the corner of the website where he can select one of his roles. if he has only 1 role there is no dropdown. Now I

ASP.NET Session_End event not firing

故事扮演 提交于 2019-12-19 07:52:17
问题 I'm trying to get a database transaction to execute when an ASP.NET session ends (in simple WebForms app on Windows 2008 Server). I realize that many respondents will suggest not to rely on the Session_End event (as I've read in a hundred forum posts on this topic yielded by a Google search). Please humor me. I've done these things: Enabled session state in web.config: <sessionState mode="InProc" cookieless="false" timeout="1" /> Confirmed that the Session_End event does NOT fire when I call

How can I use Server.MapPath() from global.asax?

蹲街弑〆低调 提交于 2019-12-18 09:59:26
问题 I need to use Server.MapPath() to combine some files path that I store in the web.config . However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its "available", I get the following exception: Server operation is not available in this context. Is there another method that can map a web root relative directory such as ~/App_Data/ to the full physical path such as C:\inetpub\wwwroot\project\App_data\ ? 回答1