473,804 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine if context is Windows Forms or Web Forms

Hello,

I have a localization class that I want to use from either Web or Windows
Forms apps. Currently it stores some information in the HttpRuntime.Cac he
object. I want to be able to determine the current context in which the
class is called. If it is called through ASP.NET, I want it to use the
HttpRuntime, but if it is called through Windows Forms app, I want it to use
a private static Hashtable.

What is the best way for an object to determine what kind of application is
calling it.

Thanks,
Arsen
Nov 17 '05 #1
6 3423
Arsen,

I think there is no (easy) way to determine the kind of app using a library.
I think the best you can do is to define a constructor for your main class
where the user of the library can explicitly indicate the kind of app he is
developing. Something like:

namespace MyLibrary
{
public enum ClientType
{ ClientTypeNotSp ecified, ClientTypeConso leApp, ClientTypeWinFo rms,
ClientTypeWebFo rms, ClientTypeWebSe rvice }

public class MainClass
{
private ClientType clientType;
public MainClass(Clien tType clientType)
{
this.clientType = clientType;
}
// rest of the methods use clientType to determine the type of app..
}
}

Regards - Octavio

"Arsen V." <ar***@communit y.nospam> escribió en el mensaje
news:OG******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have a localization class that I want to use from either Web or Windows
Forms apps. Currently it stores some information in the HttpRuntime.Cac he
object. I want to be able to determine the current context in which the
class is called. If it is called through ASP.NET, I want it to use the
HttpRuntime, but if it is called through Windows Forms app, I want it to
use
a private static Hashtable.

What is the best way for an object to determine what kind of application
is
calling it.

Thanks,
Arsen

Nov 17 '05 #2
I'm just about to run out the door now so I can't check to see if this is
100% correct but if memory serves me correctly you can use

System.Threadin g.Thread.Curren tContext

to get the current context. Not sure what you can do after that... sorry for
not being more help but I was just about to leave...

Brian Delahunty
Ireland

http://briandela.com/blog

"Arsen V." wrote:
Hello,

I have a localization class that I want to use from either Web or Windows
Forms apps. Currently it stores some information in the HttpRuntime.Cac he
object. I want to be able to determine the current context in which the
class is called. If it is called through ASP.NET, I want it to use the
HttpRuntime, but if it is called through Windows Forms app, I want it to use
a private static Hashtable.

What is the best way for an object to determine what kind of application is
calling it.

Thanks,
Arsen

Nov 17 '05 #3
Arsen,

With all due respect to the previous posters, they are wrong in their
answers. You can check the static Current property of the HttpContext
class. If it returns null, then you are not running in an ASP.NET
environment.

However, I will say this, you should at the least abstract out the
interface to access the cache/hashtable. I *think* that you can use the
ASP.NET cache in non ASP.NET situations (I don't know what makes me think
that, so don't kill me if it is not true), and if not, you could easily
generate your own cache with similar semantics.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Arsen V." <ar***@communit y.nospam> wrote in message
news:OG******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have a localization class that I want to use from either Web or Windows
Forms apps. Currently it stores some information in the HttpRuntime.Cac he
object. I want to be able to determine the current context in which the
class is called. If it is called through ASP.NET, I want it to use the
HttpRuntime, but if it is called through Windows Forms app, I want it to
use
a private static Hashtable.

What is the best way for an object to determine what kind of application
is
calling it.

Thanks,
Arsen

Nov 17 '05 #4
I never had any luck getting the ASP.NET caching mechanism to work in a
WinForms app (without jumping through hoops like hosting ASP.NET from the
WinForms app).

I definitely agree that the implementation should be abstracted.
Alternately, the OP could use a "universal" caching mechanism, such as the
MS Caching Application Block:
http://msdn.microsoft.com/library/de...l/caching1.asp

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:Os******** ******@TK2MSFTN GP14.phx.gbl...
Arsen,

With all due respect to the previous posters, they are wrong in their
answers. You can check the static Current property of the HttpContext
class. If it returns null, then you are not running in an ASP.NET
environment.

However, I will say this, you should at the least abstract out the
interface to access the cache/hashtable. I *think* that you can use the
ASP.NET cache in non ASP.NET situations (I don't know what makes me think
that, so don't kill me if it is not true), and if not, you could easily
generate your own cache with similar semantics.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Arsen V." <ar***@communit y.nospam> wrote in message
news:OG******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have a localization class that I want to use from either Web or Windows Forms apps. Currently it stores some information in the HttpRuntime.Cac he object. I want to be able to determine the current context in which the
class is called. If it is called through ASP.NET, I want it to use the
HttpRuntime, but if it is called through Windows Forms app, I want it to
use
a private static Hashtable.

What is the best way for an object to determine what kind of application
is
calling it.

Thanks,
Arsen


Nov 17 '05 #5
Jeremy,

Good idea on using the Caching Application block.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jeremy Williams" <je*********@ne tscape.net> wrote in message
news:OO******** ******@tk2msftn gp13.phx.gbl...
I never had any luck getting the ASP.NET caching mechanism to work in a
WinForms app (without jumping through hoops like hosting ASP.NET from the
WinForms app).

I definitely agree that the implementation should be abstracted.
Alternately, the OP could use a "universal" caching mechanism, such as the
MS Caching Application Block:
http://msdn.microsoft.com/library/de...l/caching1.asp

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in
message news:Os******** ******@TK2MSFTN GP14.phx.gbl...
Arsen,

With all due respect to the previous posters, they are wrong in their
answers. You can check the static Current property of the HttpContext
class. If it returns null, then you are not running in an ASP.NET
environment.

However, I will say this, you should at the least abstract out the
interface to access the cache/hashtable. I *think* that you can use the
ASP.NET cache in non ASP.NET situations (I don't know what makes me think
that, so don't kill me if it is not true), and if not, you could easily
generate your own cache with similar semantics.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Arsen V." <ar***@communit y.nospam> wrote in message
news:OG******** ******@tk2msftn gp13.phx.gbl...
> Hello,
>
> I have a localization class that I want to use from either Web or Windows > Forms apps. Currently it stores some information in the HttpRuntime.Cac he > object. I want to be able to determine the current context in which the
> class is called. If it is called through ASP.NET, I want it to use the
> HttpRuntime, but if it is called through Windows Forms app, I want it
> to
> use
> a private static Hashtable.
>
> What is the best way for an object to determine what kind of
> application
> is
> calling it.
>
> Thanks,
> Arsen
>
>



Nov 17 '05 #6
hB
else if simple work, do hashtable on both type of apps (consistent
interface that we need).
[Probably Cache object of type Static-Singleton]

---
hB

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3489
by: mh | last post by:
Hi Folks- I'm trying to do a simple emulation of unix "locate" functionality in python for windows. Problem is I don't want to crawl/index optical drives. Do any of the windows people out there know how I can determine: 1. How many drives are on the system? (I could just iterate over the alphabet os.path.exists("%s:\\"%letter) ... is there a "windows" way of
1
1279
by: Ryan Joseph So | last post by:
When you right click your mouse on the textbox it will popup a contextmenu then you can either cut, copy, paste. Is there a way to determine what process did the user choose on the context menu? And is it possible to override it meaning cancelling the process in the code. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
1722
by: cmrchs | last post by:
Hi, I am trying to create a site that will be used by both employees AND external users, so both types of users are trying to access the same pages. In the case of an employee on the intranet, authentication needs to occur via Windows integrated authentication. If the user is NOT on the intranet (external user), the user needs to be sent to a Forms login page. How does one implement this ?
0
1035
by: Rafael Veronezi | last post by:
I would like to know if there's a way to implement both Windows Integrated and Forms authentication in my Asp.net application. It's an Intranet application wich I would like to enable from inside and outside access... It would work in the following way... When the authentication is requested, the system would check if he can authenticate by windows user accounts/password. If it doesn't, he would show a authentication request, using simple...
1
1049
by: JIM.H. | last post by:
Hello, Is there a sample application in C# for windows and forms authentication, I need to create a login screen on the internet for our employees? Thanks, Jim.
2
1257
by: cmrchs | last post by:
Hi, I am trying to create a site that will be used by both employees and external users, so both types of users trying to access the same pages. In the case of an employee on the intranet, authentication needs to occur via Windows integrated authentication. If the user is NOT on the intranet (external user), the user needs to be sent to a Forms login page. Any ideas ?
1
1750
by: ABC | last post by:
I have a new project which is a web site used by Internal and External users (login required users) and public users (no login required users). On internal users, all users login network using Windows or Forms authentication login. External users will use Forms authentication login. Both authentications would be cookie or cookieless. How to config the web.config file meet the requirements?
1
301
by: Allen Maki | last post by:
Hi Everybody, I need your help. I have MS Visual Studio .NET 2003. I noticed that if I added a context menu to a form. It will not work, unless you add the line:
1
1304
by: Velvet | last post by:
I am looking for a tutorial or code samples to create a cross between Windows and Forms authentication. What we would like to do is utilize the Windows authentication for loggin into an application, but be able to set the user roles and permissions to various processes of the application in a SQL database. I have looked but I'm unable to find that wnyone else is doing this. Perhaps I'm not using the right search parameters to catch it....
1
1657
by: Chris | last post by:
Hi, we run a webapplication where users must log in. So the web.config contains: <authentication mode="Forms"/and IIS is set to Anonymous authentification. Now we want the same application to run inside our intranet. In this case, windows authentification must be used, avoiding to have to log a second time. Is it possible to put together in web.config both
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.