Http - Get Application Path Without Using Httpcontext?

Mar 9, 2010

How to do it?I don't want to use this:

HttpContext.Current.Server.MapPath

Is there a similar function that I can call without requiring a httpcontext?For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it from a shared var.

View 1 Replies


Similar Messages:

C# - Determine The Physical Path Of A File Without An HttpContext?

Aug 23, 2010

I have some processes that run without an HttpContext in an ASP.NET MVC web application. This process needs to be able to determine the physical path to the Contents directory of the application for reading/writing data. But, since it is without an HttpContext, I don't get to use fancy things like Server.MapPath and such.

View 2 Replies

Asynchronous HTTP Handler And Using HttpContext In A Background Thread?

Feb 10, 2010

I was reading Walkthrough: Creating an Asynchronous HTTP Handler and noticed they pass the HttpContext from the handler thread and use it in a WaitCallback which runs on a background thread. It makes calls like _context.Response.Write(). Am I correct in assuming that this doesn't violate the fact that HttpContext is not thread safe because the handler thread will not be using it after the async work has started?

Also, Using an HTTPContext across threads has some good information about HttpContext and threads. Is all of HttpContext not thread safe, or just items like Response? Can multiple background threads access the Items property, if only in read mode?

View 1 Replies

HttpContext.Current.Items Reused Across Multiple Http Requests?

Jan 27, 2011

I'm using HttpContext.Current.Items to make a Per-Request Cache Store. I'm hitting to many Cache entries over different http requests.

It seems that HttpContext.Current.Items is reused across multiple http requests. Is it normal?

View 2 Replies

IIS7 Application Configuration - Placing Into Single Physical Path And Creating Multiple Pointing To That Path

Dec 20, 2010

I have a custom ASP.NET application that I utilize for several clients that I host. Each client has a separate domain and the application is normally a child application under the root domain [URL]. The application files are the same (aspx, ascx, style sheets, images, etc.). The only thing different is the web.config file for each client. As development of the application continues to evolve, I have to update the application for each directory and this obviously becoming tedious. I am trying to come up with a method keep the application up to date. My first though is placing the application into a single physical path and creating multiple applications pointing to that path (the problem with this method is I can't have different web.config files). I am curious as to what solution others are using in this scenario...

View 2 Replies

C# - Convert Image Path To Http Url?

Jan 24, 2011

a third party API doesn't consider image path and display nothing in image,,instead a http URL works.

I am creating a webservice and My requirement is to

Convert an image path to a http url..

for example instead of http://office.microsoft.com/global/images/mypic.jpg

i want

http://office.microsoft.com/global/images/default.aspx?assetid=ZA103873861033

View 3 Replies

Get Http Url Path Of Local File On Server?

Dec 4, 2010

I'm using ASP.NET with MVC 2 and have trouble translating a local file url to a server address. It would seem like a fairly simple and common task, but google searches gives me no good answers. (Perhaps i suck at searching)

I have a controller that takes a file from a html form in a view and saves it to disk. I need to return the real url of this file back to the View. Whatever method i use, I always get a string with the local path of the file instead of the http path.

I suspect the url might get translated to http address once the project has been deployed, but I really need the server address when debugging without having to hardcode anything.

Consider the following example in some controller method:

string url = Url.RequestContext.HttpContext.Server.MapPath("~/Content/Files/" + Path.GetFileName(file.FileName));
// outputs: "C:\Users\xxx\Documents\Visual Studio 2010\Projects\[ProjectName]\Content\Files\file.png"
// whereas i'd like something like "http://localhost/Content/Files/file.png" instead

View 1 Replies

C# - HTTP Verb POST Used To Access Path Not Allowed

Mar 8, 2011

I am not using URL Rewriting, my app works fine until I try to hit a .PDF file or even a .TXT file via a link that I have dynamically generated into the PostBackUrl of a LinkButton. The path is correct. I have thoroughly researched this issue on here and most of the issues are with people using a POST action or not or the URL Rewriting, which I am not. In IIS Error looks like:

Server Error in Application "DEFAULT WEB SITE/EVENTS"Internet Information Services 7.5
Error Summary
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used. Detailed Error Information
Module StaticFileModule
Notification ExecuteRequestHandler
Handler StaticFile
Error Code 0x80070001
Requested [URL]
Physical Path C:projectsEventsEventDocs48ea946f-e948-e011-ad73-00155d0e670b2011.pdf

Code to dynamically generate the url to click to is here:

public void DocumentsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton LinkToDoc = (LinkButton)e.Item.FindControl("LinkToDoc");
Label FileNameLabel = (Label)e.Item.FindControl("FileNameLabel");
LinkToDoc.PostBackUrl = "~/EventDocs/" + SessionValue.EventId.ToString() + "/" + FileNameLabel.Text;
LinkToDoc.Text = FileNameLabel.Text;
}

View 3 Replies

C# - Hide An Image Path On Asp Page Without Http Handler?

Apr 20, 2010

I have many static images under a directory in my site structure, and I'm not concerned with hotlinking or copy-protecting the images. For a myriad of reasons, what I need to do is not show the image path on the site (or show a fake one).

Is there any way to do this without resorting to an http handler or a worker asp.net page?

View 2 Replies

C# - How To Access HttpContext.Current.Application

Jun 7, 2010

i have problem accessing HttpContext.Current.Application From global.asax its seems to be null every time i try to access it. How can i to this?

HttpContext.Current.Application.Lock();
HttpContext.Current.Application["Actions"] = "hello";
HttpContext.Current.Application.UnLock();

View 2 Replies

The HTTP Verb POST Used To Access Path '/test.html' Is Not Allowed

Feb 5, 2010

Below is my code:

[code]....

The HTTP verb POST used to access path '/test.html' is not allowed

View 4 Replies

HttpContext.Current.Application During Load Balancing

Oct 13, 2010

I wanted to understand the behavior of HttpContext.Current.Application during the load balancing. I have read that session can be stored in disk hence can be retrieved from different servers. Is this true for HttpContext.Current.Application also. Does the keydata stored in one machine is accessible in other different machine too?

View 1 Replies

C# - How To Get The Physical Location Of Web Application Without Using HttpContext.Current

Jun 11, 2010

I've found myself having a requirement to configure log4net based on a file relative to the physical location of the running ASP.NET web application. We like to start the logger as early as possible, so Application_Start seems a proper place. In IIS6, this works fine and has been running for ages, but now we moved to IIS7 and this won't work anymore:

string absolutePath = HttpContext.Current.Request.PhysicalApplicationPath;

because the HttpContext.Current is not available in many global.asax (Application, Session) events. This is old news, we all know it raises the now infamous Request is not available in this context error. We don't want to move back to Classic Mode.

Now, the question is simple: without using HttpContext, is it possible to find the physical location of the currently running web application instance?

View 2 Replies

Programmatically Set HttpContext.Handler In Classic Application?

Feb 24, 2010

In my CMS application, I'm trying to intercept all ASP.NET requests, inspect them and then assign custom HttpHandler if necessary or leave default handling when appropriate.I tried setting HttpContext.Current.Handler in Application_BeginRequest but it doesn't seem to work.There is MapRequestHandler event in HttpApplication but it is not available in the Global application class.

View 1 Replies

C# - Workaround For HttpContext.HideRequestResponse Being Internal? Detect If HttpContext.Request Is Really Available?

Apr 9, 2010

We're migrating an application to use IIS7 integrated mode. In library code that is designed to work either within the context of an HTTP request or not, we commonly have code like this:

if (HttpContext.Current != null &&
HttpContext.Current.Request != null) {
// do something with HttpContext.Current.Request
} else {
// do equivalent thing without HttpContext..
}

But in IIS7 integrated mode the check for HttpContext.Current.Request throws an exception whenever this code is called from Application_Start.

protected void Application_Start(object sender, EventArgs e)
{
SomeLibrary.DoSomethingWithHttpContextCurrentDetection();
}

Results in:

System.Web.HttpException: Request is not available in this context

How can I detect whether the request is really available without wrapping these calls in an exception handler and taking action based on whether an exception is generated or not.

Looking at HttpContext in Reflector I see it has an internal bool HideRequestResponse field but it's internal so I can only get to it with reflection and that's fragile. Is there a more official/approved way to determine if it's ok to call HttpContext.Request?

This blog post about the subject says not to use HttpContext, but how, in generic library code, can you determine if it's ok to use HttpContext?

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

I'm using the work-around mentioned there which is to use Application_BeginRequest and an initialized field to only initialize once as part of BeginRequest, but that has to be done in every calling application whereas I'd prefer to make the library code more robust and handle this situation regardless of where it's called from.

View 4 Replies

C# - Rootlevel HTTP Module - Unable To Understand The Master Page Path In The Virtual Directory

Mar 1, 2011

I have a http module at root level which resolves to the virtual directory which is a .net application on some conditions as below.

I need the have the httpmodule at root level only for some requirements.

application.Context.RewritePath("/virtualdirecotry/root/pages/sample/sample.aspx", String.Empty, "");

the sample.aspx page uses a master page as below

<%@ Page Language="C#" MasterPageFile="~/Root/Pages/Master/Site.Master"

as it uses the relative path the http module is unable to understand the path and throwing following error

The file '/Root/Pages/Master/Site.Master' does not exist.

error occurred during the parsing of a resource required to service this request. review the following specific parse error details and modify your source file appropriately.

View 1 Replies

C# - Identify From HttpContext Object That Requesting Application Or Browser Is Cookieless?

Dec 30, 2010

How can i identify just from the HttpContext Object that the HttpRequest coming to my application is from a cookieless application or cookieless browser?

View 2 Replies

Get Application File Path In Windows Forms Application?

Nov 3, 2010

I have a simple windows form app that I need to get the file path for. I am placing a config file in the same directory and I need to be able to get the path to that file.

I have used
Application.CommonAppDataPath
but that returns the path with 1.0.0.0 at the end.

and
Applicaiton.StartupPath
but that returns the path with indebug at the end

Is there anyway to get the path to just the main file directory without anything appended to the end?

View 3 Replies

Configuration :: Set Application Path To Run Application From Anywhere

Sep 8, 2010

Am currently work on web application..sometime i need to run my project files from diffrent computers. everytime i run my application in different computers i have to set up data source connection. how can i avoid it? can i run the project from anywhere without set connection to database?how to make it?

View 2 Replies

Finding Difference System.web.httpcontext.current.application And System.Configuration.Appsettings?

Jan 22, 2010

Can anyone tell me the differnce between

System.web.httpcontext.current.application["tag"]

or

System.Configuration.Appsettings["tag"]

View 2 Replies

C# - Get The Application Path?

Nov 28, 2010

how to get the application path ? bin path in asp.net

View 2 Replies

C# - Programmatically Set HTTP Handlers In .NET Application?

Nov 4, 2010

I need to dynamically instantiate a web application from a console application. By this definition, I mean that my console application contains a web application that is not bound to IIS/XSP.Currently, I create the web application into a temporary directory and copy some forged files into it. These are a special Global.asax that maps to my own implementation of HttpApplication to use in the web application (I need to do some initialization at app start), then I forge special .asmx files that map to my own skeleton classes and dynamic plugins

foreach (IPlugin plugin in _target.Plugins)
{
WsdlSkeletonDefinition[] defs = plugin.GetWsdlSkeletons();

My approach works, but I'm not so satisfied by it because I have to write lots of garbage into file system, even if I eventually delete it all.I know I can control HTTP handlers via Web.config, but I don't want to forge a Web.config for that. I would like to create a mapping such as I can remove the .asmx extension from web services' URLs and still get them.For example, one of the default scripts is "LogbusManagement.asmx", which must be hard-coded into client APIs and the .asmx prevents portability to other platforms such as PHP. I want to make "LogbusManagement.asmx" equivalent to "LogbusManagement" and any extension. For this, I might use an HttpHandlerFactory.

My straight question is,like asked here by somebody else: is there a way to programmatically, possibly from Global.asax, to set IHttpHandlers or IHttpHandlerFactories for web applications?

View 1 Replies

Relationship Between HttpContext.Request.Cookies And HttpContext.Response.Cookies

Nov 23, 2010

I have been experimenting with code that will clear all of the cookies in an HttpContext.Response.Initially, I used this:

DateTime cookieExpires = DateTime.Now.AddDays(-1);
for (int i = 0; i < HttpContext.Request.Cookies.Count; i++)
{
HttpContext.Response.Cookies.Add(
new HttpCookie(HttpContext.Request.Cookies[i].Name, null) { Expires = cookieExpires });
}

this will error with an OutOfMemoryException because the for loop never exits - each time you add a cookie to the Response, it also gets added to the `Request.

View 1 Replies

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

Install An Application On A UNC Path, It's Possible

Aug 18, 2010

I am planning to deploy an ASP.NET application to a UNC path and create a virtual directory that points to the UNC path.For example the location of the ASP.NET application would be:

\server01myFirstApplication
Instead of:
C:InetpubwwwrootmyFirstApplication

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved