global-asax

“System.Web.HttpException: Response is not available in this context” only in IIS

倖福魔咒の 提交于 2019-12-08 03:56:10
问题 i have used the Http.Current.Response in my global.asax.cs Application Start. It is working fine without any issue when i execute in my PC. How ever when i try to put it in IIS with Windows Server 2008 R2, i find that it is giving the following error. the code for it is public static void SetCookie(string key, string value, int dayExpires) { HttpCookie encodedCookie = HttpSecureCookie.Encode(new HttpCookie(key, value)); encodedCookie.Expires = DateTime.Now.AddDays(dayExpires); HttpContext

Register RazorViewEngine only for C# (only for .cshtml files)

南楼画角 提交于 2019-12-07 20:13:12
问题 I am only using RazorViewEngine on one of my ASP.NET MVC 3 applications and I cleared Web Forms view engine out with following code inside Application_Start method of my Global.asax.cs file ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); I decided to see something solid so that I could be satisfied with this two-line-code-effort and I try to render a partial view which does not exist and I got this result : The partial view '_ResortMapPartialView' was not found or

redirecting w., ww., wwww. to -> www

喜欢而已 提交于 2019-12-07 19:49:45
问题 I'm trying to redirect site.com w.site.com ww.site.com and wwww.site.com to www.site.com. My boss wants to ensure typos make it to the site as well. They redirect fine. I'm using ASP.Net and throw a 301 redirect back using a regular expression, however, tools such as http://www.seoconsultants.com/tools/headers.asp don't seem to show a correct redirect when I try to use w.site.com ww. etc. I'm trying to figure out what google sees, but I'm not sure where to check. It would "appear" that

“System.Web.HttpException: Response is not available in this context” only in IIS

空扰寡人 提交于 2019-12-07 18:41:29
i have used the Http.Current.Response in my global.asax.cs Application Start. It is working fine without any issue when i execute in my PC. How ever when i try to put it in IIS with Windows Server 2008 R2, i find that it is giving the following error. the code for it is public static void SetCookie(string key, string value, int dayExpires) { HttpCookie encodedCookie = HttpSecureCookie.Encode(new HttpCookie(key, value)); encodedCookie.Expires = DateTime.Now.AddDays(dayExpires); HttpContext.Current.Response.Cookies.Remove(key); HttpContext.Current.Response.Cookies.Add(encodedCookie); } I wanted

Request is not available in this context -> In Global.asax -> what is replace

℡╲_俬逩灬. 提交于 2019-12-07 12:08:30
问题 why the below line has error in global.asax : string RelativeFilePath = "~/" + (AbsoluteFilePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty)).Replace("\\", "/"); Error : Request is not available in this context what is the replacement? thanks in advance 回答1: If you are hosting your application in IIS7 integrated pipeline HttpContext objects are not available in Application_Start . For your scenario you could do this instead: string relativeFilePath = "~/" +

How do I detect if a request is a callback in the Global.asax?

依然范特西╮ 提交于 2019-12-07 10:05:40
问题 I need to find a way to detect if a request is a callback when the Application_BeginRequest method is called. Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)<br /> Dim _isCallBack As Boolean = False ' Code to set _isCallBack is True or False Here If Not _isCallBack Then '... Some Code End If End Sub I need to know what to replace "[Code to set _isCallBack is True or False Here]" with. 回答1: This may help you: http://msdn.microsoft.com/en-us/magazine/cc163941.aspx

Can you run a “service” that runs a scheduled task from an ASP.Net project?

孤街醉人 提交于 2019-12-07 05:38:42
问题 I built a Windows Service for a client of ours that collects all the changed/new rows from the database, turns them into a CSV and FTP uploads them somewhere every night. Now as it turns out they don't have access to install or run a Windows Service (it's a web path only hosted solution). I thought it would be easy enough to modify the Windows Service code to run inside the ASP.Net process and instantiated from the Global.asax (I've done this in the past, hosting a WCF service from within a

ASP.NET MVC routing conflict - null value for input variable

夙愿已清 提交于 2019-12-07 03:41:44
问题 I'm at a loss as to why my routes are conflicting. I have these in my Global.asax file: routes.MapRoute( "CustomerView", "{controller}/{action}/{username}", new { controller = "Home", action = "Index", username = "" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "0" } ); So far everything has worked fine except when I created a controller action like so: public ActionResult MyAction(int id) { //Do stuff here return View(); }

Check for a static file during Application_BeginRequest?

帅比萌擦擦* 提交于 2019-12-07 03:22:38
问题 I have a Global.asx file that needs to do custom authentication, auditing and profiling stuff. This is needed because it supports a SAML based SSO system and needs to override the normal .Net authentication (which doesn't support either SAML or mixed authentication) I don't want to fire it for static files, such as .js , .css , .png , etc In Cassini/WebDev and IIS7 it does. What I want to have is some simple check, like a this.Request.IsStaticFile (which doesn't exist, unfortunately) to

Read HttpContext.Current.Response.OutputStream in Global.asax

旧巷老猫 提交于 2019-12-07 02:46:46
问题 How I can read the whole content of HttpContext.Current.Response.OutputStream in Global.asax End_Request? I want to get the text of content that is sent to browser? I tried to google it, but didn't found something useful. Actually I hope this is possible and I will not need to create a filter or something for this simple requirement. Thank you. 来源: https://stackoverflow.com/questions/16189834/read-httpcontext-current-response-outputstream-in-global-asax